I’m not sure if there is a more efficient way of doing what I’m doing using LINQ… I have two enumerations:
enumA(string): { "Andy", "Bill", "Charlie", "Doug" }
enumB(foo): { "Doug", "Edward", "George", "Bill" } (Note that enumB actually contains objects)
var dictionary = new Dictionary<string,
foreach (var a in enumA)
{
var b = enumB.SingleOrDefault(x => String.Equals(x.ToString(), a));
if (b != null)
dictionary[a] = b;
}
It just seems bad to me to enumerate over enumB over and over again and create a dictionary this way when I’m sure there is probably a more “correct” way to create a dictionary using LINQ.
You can do it efficiently using a
and an
call afterwards.