Is there a <NotIn> LINQ method?

Is there a NotInLINQ method ?

// A: 1,2,3,4,5
// B: 4,5,6,7,8

C = A.NotIn(B);

// C: 1,2,3
+3
source share
3 answers

IEnumerable<T>.Except

var a = new int[] {1, 2, 3, 4, 5};
var b = new int[] {4, 5, 6, 7, 8};
var c = a.Except(b);
foreach(var x in c)
    Console.WriteLine(x);

output:

1
2
3
+6
source

Yes it is. He is called Except.

So in your case C = A.Except(B);

+2
source

It will be Except(assuming that Aand Bare listed):

var C = A.Except(B);
+2
source

All Articles