kartal kartal - 1 year ago 69
C# Question

Get distinct list between two lists in C#

I have two lists of strings. How do I get the list of distinct values between them or remove the second list elements from the first list?

List<string> list1 = { "see","you","live"}

List<string> list2 = { "see"}

The result should be

Answer Source

It looks to me like you need Enumerable.Except():

var differences = list1.Except(list2);

And then you can loop through the differences:

foreach(var difference in differences)
    // work with each individual string here.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download