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
class Program{ static void Main(string[] args){ var listA = Enumerable.Range(1, 6); var listB = new List{ 3, 4 }; var listC = listA.Except(listB); foreach (var item in listC){ Console.WriteLine(item); } Console.ReadLine(); } }
In the above example we have two list, and we only get those results from list A that are not in list B
1 2 5 6
Use Sql-like syntax
static void Main(string[] args){ var listA = Enumerable.Range(1, 6); var listB = new List{ 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(); }
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!