Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a <NotIn> LINQ method?

Tags:

c#

linq

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
like image 679
Homam Avatar asked Dec 14 '25 12:12

Homam


2 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
like image 82
Jamiec Avatar answered Dec 17 '25 04:12

Jamiec


Yes it is. It's called Except.

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

like image 40
Øyvind Bråthen Avatar answered Dec 17 '25 04:12

Øyvind Bråthen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!