Search code examples
c#linqexcept

Add a static value in list when using Except


I am using two lists

List<int> a = {1,2,3};
List<int> b = {3};

and using Except to compare and filter them.

var diff = a.Except(b).ToList();

this returns values as

1
2

I need to return a bool value along with that ie. the return values should be as

1 true
2 true

the return type is a List<modelClass> that has int id, bool isTrue properties

Can you help me in doing this ?


Solution

  • Can't you just do this:

    var diff = a.Except(b)
                .Select(s=>new modelClass(){id = s, isTrue = true})
                .ToList();