I have two lists
list 1 = { "fred", "fox", "jumps", "rabbit"};
list2 ={"fred", "jumps"}
Now I need to get a list3 which contains elements of list1 which are not present in list2.
so list 3 should be
list3 = {"fox", "rabbit"};
I can do this manually by using loops but I was wondering if there is something like list3 = list1 – list2 or some other better way than using loops.
Thanks
If you are using .NET 3.5 or newer then you can use
Enumerable.Except:If you want it as a list:
For older versions of .NET you could insert the strings from list1 as keys in a dictionary and then remove the strings from list2, then the keys that are left in dictionary is the result.