Aggregation
Aggregate, Average, Count, LongCount, Max, Min, Sum
Conversion
AsEnumerable, Cast, OfType, ToArray, ToDictionary, ToList, ToLookup
Element
ElementAt, ElementAtOrDefault, First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault
ElementAt
ElementAtOrDefault
First (simple)
First (conditional)
FirstOrDefault
Last
LastOrDefault (simple)
LastOrDefault (conditional)
Single
SingleOrDefault
Generation
DefaultIfEmpty, Empty, Range, Repeat
Grouping
GroupBy
Join
GroupJoin, Join
Ordering
OrderBy, OrderByDescending, Reverse, ThenBy, ThenByDescending
OrderBy (simple - numbers)
OrderBy (simple - dates)
OrderBy (simple - objects)
OrderByDescending
Reverse
ThenBy
ThenByDescending
Other
Concat, SequenceEqual, Zip
Partitioning
Skip, SkipWhile, Take, TakeWhile
Projection
Select, SelectMany
Quantifiers
All, Any, Contains
Restriction
Where
Set
Distinct, Except, Intersect, Union
Close
Except: Removes all elements from one collection which exist in another collection.
Except: Removes all elements from one collection which exist in another collection. |
Except: Removes all elements from one collection which exist in another collection. |
This Query Expression sample removes numbers from "numbers1", which exist in "numbers2". |
This Query Expression sample removes numbers from "numbers1", which exist in "numbers2". |
static void Sample_Except_Linq() { int[] numbers1 = { 1, 2, 3 }; int[] numbers2 = { 3, 4, 5 }; var result = (from n in numbers1.Except(numbers2) select n); Debug.WriteLine("Except creates a single sequence from numbers1 and removes the duplicates found in numbers2:"); foreach (int number in result) Debug.WriteLine(number); }Output:
Except creates a single sequence from numbers1 and removes the duplicates found in numbers2: 1 2
Private Shared Sub Sample_Except_Linq() Dim numbers1 As Integer() = {1, 2, 3} Dim numbers2 As Integer() = {3, 4, 5} Dim result = From n In numbers1.Except(numbers2) Select n Debug.WriteLine("Except creates a single sequence from numbers1 and removes the duplicates found in numbers2:") For Each number As Integer In result Debug.WriteLine(number) Next End SubOutput:
Except creates a single sequence from numbers1 and removes the duplicates found in numbers2: 1 2
let Sample_Except_Linq() = let numbers1 = [| 1; 2; 3 |] let numbers2 = [| 3; 4; 5 |] let result = query { for n in numbers1.Except(numbers2) do select n } Debug.WriteLine(sprintf "Except creates a single sequence from numbers1 and removes the duplicates found in numbers2:") for number in result do Debug.WriteLine(sprintf "%d" number)Output:
Except creates a single sequence from numbers1 and removes the duplicates found in numbers2: 1 2
static void Sample_Except_Lambda() { int[] numbers1 = { 1, 2, 3 }; int[] numbers2 = { 3, 4, 5 }; var result = numbers1.Except(numbers2); Debug.WriteLine("Except creates a single sequence from numbers1 and removes the duplicates found in numbers2:"); foreach (int number in result) Debug.WriteLine(number); }Output:
Except creates a single sequence from numbers1 and removes the duplicates found in numbers2: 1 2
Private Shared Sub Sample_Except_Lambda() Dim numbers1 As Integer() = {1, 2, 3} Dim numbers2 As Integer() = {3, 4, 5} Dim result = numbers1.Except(numbers2) Debug.WriteLine("Except creates a single sequence from numbers1 and removes the duplicates found in numbers2:") For Each number As Integer In result Debug.WriteLine(number) Next End SubOutput:
Except creates a single sequence from numbers1 and removes the duplicates found in numbers2: 1 2
let Sample_Except_Lambda() = let numbers1 = [| 1; 2; 3 |] let numbers2 = [| 3; 4; 5 |] let result = numbers1.Except(numbers2) Debug.WriteLine(sprintf "Except creates a single sequence from numbers1 and removes the duplicates found in numbers2:") for number in result do Debug.WriteLine(sprintf "%d" number)Output:
Except creates a single sequence from numbers1 and removes the duplicates found in numbers2: 1 2