Arane
Arane

Reputation: 323

Grab the missing value after comparing 2 lists

I currently have two lists

List<string> original = new List<string>();
List<string> edited = new List<string>();


List A            List B
------            ------
   1                 1
   2                 2
   3

I want to grab and display the value that is unable to be matched after comparing (which is 3 in the above example)

Upvotes: 1

Views: 56

Answers (2)

mybirthname
mybirthname

Reputation: 18127

var notMatched = original.Except(edited).ToList();

EDIT:

If you have multiple mismatched values with same value and want to be shown just once:

var notMatched = original.Except(edited).Distinct().ToList();

Upvotes: 3

radarbob
radarbob

Reputation: 5101

i am not really familiar and into using of lambda expressions. i was thinking of using a foreach perhaps.

Don't need a loop.

    List<string> deletedStuff= new List<string>();
    deletedStuff.AddRange( original.FindAll( x => ! edited.Contains( x ) ).AsEnumerable());

Upvotes: 0

Related Questions