I have two Collection of List<string> if value is not found in one List it should remove that value from Second List<string>
for e.g
List<string> ob = new List<string> { "one", "two", "three" };
List<string> ob1 = new List<string> { "one", "two", "four" };
so when i compare the values in ob and ob1 if "three" is not found in ob1 it should remove it and if any new value found like "four" it should add to ob
so my Final Collection values in ob will be {"one","two","four"};
(b) foreach item in your first list, search your master list; if the item is found, add it to the
List<String> created in step (a)
(c) when you've iterated through all of the items in your first list, then assign the third list to the first list.
tan_vision_12_2010
so my Final Collection values in ob will be {"one","two","four"};
WHY? from your example, ob does not have the value "four" ... so why have you added "four" to
ob?????????
Please clarify.
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
Marked as answer by Amy Peng - MSFT on Jan 17, 2013 12:46 AM
tan_vision_1...
Participant
1179 Points
416 Posts
Manipulation with List<T>
Jan 08, 2013 10:42 AM|LINK
I have two Collection of List<string> if value is not found in one List it should remove that value from Second List<string>
for e.g
List<string> ob = new List<string> { "one", "two", "three" };
List<string> ob1 = new List<string> { "one", "two", "four" };
so when i compare the values in ob and ob1 if "three" is not found in ob1 it should remove it and if any new value found like "four" it should add to ob
so my Final Collection values in ob will be {"one","two","four"};
any help
Thanx
gerrylowry
All-Star
20577 Points
5721 Posts
Re: Manipulation with List<T>
Jan 08, 2013 11:35 AM|LINK
@ tan_vision_12_2010
TIMTOWTDI =. there is more than one way to do it
Here is one approach in pseudo code:
(a) create a third List<String>
(b) foreach item in your first list, search your master list; if the item is found, add it to the List<String> created in step (a)
(c) when you've iterated through all of the items in your first list, then assign the third list to the first list.
WHY? from your example, ob does not have the value "four" ... so why have you added "four" to ob?????????
Please clarify.
g.
Paul Linton
Star
13571 Points
2571 Posts
Re: Manipulation with List<T>
Jan 08, 2013 08:42 PM|LINK
From your description the end result is that ob is a copy of ob1.
ob = ob1.Select(o=>o).ToList();