I have a generic list filled with items. In this list I have one column which is unique (like an ID). And I have another generic list with other items and the same ID column. This is the way I fill the items to the lists:
foreach (string s in l1)
{
GridViewSource src = new GridViewSource();
src.test = "id" + s;
list.Add(src);
}
foreach (string s in l2)
{
GridViewSource src = new GridViewSource();
src.test = "id" + s;
src.test2 = "somerandomtext" + s;
list2.Add(src);
}
What I'm trying to do is to add items from list2 to list if they have the same ID. So it should add an item from list2 with the ID "id3" to the item "id3" of list. Like merging. I don't want to add them to the bottom of the list or insert them between the items. I tried Concat method but it's just adding the items add the end of the list:
list = list.Concat(list2).ToList();
EDIT:
I try to explain it another way:
My list looks like this:
[0] => test = "id1", test2 = ""
[1] => test = "id2", test2 = ""
[2] => test = "id3", test2 = ""
[3] => test = "id4", test2 = ""
[4] => test = "id5", test2 = ""
And my list2 looks like this:
[0] => test = "id1", test2 = "somerandomtext1"
[1] => test = "id2", test2 = "somerandomtext2"
[2] => test = "id3", test2 = "somerandomtext3"
And when I merge the lists, it should look like this:
[0] => test = "id1", test2 = "somerandomtext1"
[1] => test = "id2", test2 = "somerandomtext2"
[2] => test = "id3", test2 = "somerandomtext3"
[3] => test = "id4", test2 = ""
[4] => test = "id5", test2 = ""
But it looks like this:
[0] => test = "id1", test2 = ""
[1] => test = "id2", test2 = ""
[2] => test = "id3", test2 = ""
[3] => test = "id4", test2 = ""
[4] => test = "id5", test2 = ""
[5] => test = "id1", test2 = "somerandomtext1"
[6] => test = "id2", test2 = "somerandomtext2"
[7] => test = "id3", test2 = "somerandomtext3"
Any suggestions?