I'm using VS 2008. I pass a List<T> a
using ref
, along with another List<T> b
.
I need to cycle thru List<T> b
, which contains around 200,000 items, and for each item in b
, it it matches criteria in a
, which contains 100,000 or more items, and update it.
public static void UpdateList(ref List<ExampleT> a, List<ExampleT> b)
{
var count = 0;
for (int i = 0; i < b.Count; i++)
{
foreach (var z in a.FindAll(x => x.MatchA == b[i].MatchA && x.MatchB == b[i].MatchB))
{
z.ToUpdate = b[i].ToUpdate;
count++;
}
if(count >= 10000)
break;
}
}
Now, the only reason I added count
was so that once 10000 items in a
have been updated, the loop will stop, otherwise it will take a very long time to go thru all of the items. Even by limiting it like this, it still takes around 3 min.
For the sake of the example, T in this case is an object similar to the following:
public class ExampleT
{
public string MatchA {get;set;}
public string MatchB {get;set;}
public double? ToUpdate {get;set;} //in List a this will ALWAYS be null until it gets updated in the foreach
}
Is there a way I can make this more efficient?
a
by reference in your code. \$\endgroup\$