The Except operator is designed to allow you to query data that supports the IEnumerable Except operator displays all items in one list minus the items in the second list In the above example we have two list, and we only get those results from list A that are not in list B Use Sql-like syntaxExample 1
class Program{
static void Main(string[] args){
var listA = Enumerable.Range(1, 6);
var listB = new List<int> { 3, 4 };
var listC = listA.Except(listB);
foreach (var item in listC){
Console.WriteLine(item);
}
Console.ReadLine();
}
}
Output
1
2
5
6
Example 2
static void Main(string[] args){
var listA = Enumerable.Range(1, 6);
var listB = new List<int> { 3, 4 };
var listC = from c in listA
where !listB.Any(o => o == c)
select c;
foreach (var item in listC){
Console.WriteLine(item);
}
Console.ReadLine();
}
Output
1
2
5
6
The above is the detailed content of How to use 'not in' query in C# LINQ?. For more information, please follow other related articles on the PHP Chinese website!