I have two Lists:
List<Item1> list1;
List<Item2> list2;
I have following code for compearing items in Lists:
ConcurrentDictionary<string, string> compareDictionary = new ConcurrentDictionary<string, string>();
for (int i = 0; i < lis1.Count; i++)
{
var item1Name= list1[i].Name.ToString();
var item1Id= list1[i].ID.ToString();
foreach (var item in list2)
{
if (item1Name.Contains(item.item2Name.ToLower()))
{
compareDictionary.TryAdd(item1Id, item.item2Id);
}
}
}
It is needed to add Id
from the first List an Id
from the second one into ConcurrentDictionary, if Name
of one item contains part of another one.
It works, but I want to simplify the algorithm and remove the foreach
and if
.