I have two type instances IEnumerableas follows.
IEnumerable<Type1> type1 = ...;
IEnumerable<Type2> type2 = ...;
Both Type1and Type2contain a member called common, so, even though they are of different class, we can still link them as follows.
type1[0].common == type2[4].common
I am trying to filter out those elements Type1that do not have a corresponding value commonin Type2, and create a dictionary based on one value from each. Right now, I am doing this with the following double loop.
Dictionary<String, String> intersection = ...;
foreach (Type1 t1 in type1)
foreach(Type2 t2 in type2)
if (t1.common == t2.common)
intersection.Add(t1.Id, t2.Value);
Now I tried with LINQ, but thatβs all .Where, .Selectand .ForEachjust gave me a headache. Is there a way to neatly perform the same operation using LINQ?
user1675891
source
share