Jay S

Jay S

  • NA
  • 230
  • 57.8k

Quickest Loop within a Loop

Sep 9 2014 11:48 AM
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)