2
Answers

Quickest Loop within a Loop

Jay S

Jay S

10y
744
1
Currently I have a Loop with in a Loop to find if sometime in a List is contained within a string array:


            foreach (var cl in compFileName)
            {
                foreach (var f in fileArray)
                {
                    if (f.Contains(cl))
                    {
                        compToCopy.Add(f);
                    }
                }
                (sender as BackgroundWorker).ReportProgress(i, Convert.ToString(i));
                i++;

I'm wondering if there is a more efficient way rather than doing a loop within a loop as even with just 30,000 in the list it takes some time to iterate through!



Answers (2)