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
OfType: Filters elements of specified type in a collection.
OfType: Filters elements of specified type in a collection. |
OfType: Filters elements of specified type in a collection. |
This Lambda Expression sample takes only objects of type string. |
This Lambda Expression sample takes only objects of type string. |
static void Sample_OfType_Linq() { object[] objects = { "Thomas", 31, 5.02, null, "Joey" }; var result = from o in objects.OfType<string>() select o; Debug.WriteLine("Objects being of type string:"); foreach (string str in result) Debug.WriteLine(str); }Output:
Objects being of type string: Thomas Joey
Private Shared Sub Sample_OfType_Linq() Dim objects As Object() = {"Thomas", 31, 5.02, Nothing, "Joey"} Dim result = From o In objects.OfType(Of String)() Debug.WriteLine("Objects being of type string:") For Each str As String In result Debug.WriteLine(str) Next End SubOutput:
Objects being of type string: Thomas Joey
let Sample_OfType_Linq() = let objects : obj[] = [|"Thomas"; 31; 5.02; null; "Joey"|] let result = query { for o in objects.OfType<string>() do select o } Debug.WriteLine(sprintf "Objects being of type string have the values:") for str in result do Debug.WriteLine(sprintf "%s" str)Output:
Objects being of type string have the values: Thomas Joey
static void Sample_OfType_Lambda() { object[] objects = { "Thomas", 31, 5.02, null, "Joey" }; var result = objects.OfType<string>(); Debug.WriteLine("Objects being of type string have the values:"); foreach (string str in result) Debug.WriteLine(str); }Output:
Objects being of type string have the values: Thomas Joey
Private Shared Sub Sample_OfType_Lambda() Dim objects As Object() = {"Thomas", 31, 5.02, Nothing, "Joey"} Dim result = objects.OfType(Of String)() Debug.WriteLine("Objects being of type string have the values:") For Each str As String In result Debug.WriteLine(str) Next End SubOutput:
Objects being of type string have the values: Thomas Joey
let Sample_OfType_Lambda() = let objects : obj[] = [|"Thomas"; 31; 5.02; null; "Joey"|] let result = objects.OfType<string>(); Debug.WriteLine(sprintf "Objects being of type string have the values:") for str in result do Debug.WriteLine(sprintf "%s" str)Output:
Objects being of type string have the values: Thomas Joey