Homam
Homam

Reputation: 23871

Is there a <NotIn> LINQ method?

Is there a NotIn LINQ method ?

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

C = A.NotIn(B);

// C: 1,2,3

Upvotes: 3

Views: 181

Answers (3)

Jamiec
Jamiec

Reputation: 136174

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

Upvotes: 6

Anton Gogolev
Anton Gogolev

Reputation: 115857

That will be Except (assuming A and B are enumerable):

var C = A.Except(B);

Upvotes: 2

&#216;yvind Br&#229;then
&#216;yvind Br&#229;then

Reputation: 60724

Yes it is. It's called Except.

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

Upvotes: 2

Related Questions