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
Cast: Casts a collection to a specified type.
Cast: Casts a collection to a specified type. |
Cast: Casts a collection to a specified type. |
This Lambda Expression sample casts list of strings to a simple string array. |
This Lambda Expression sample casts list of strings to a simple string array. |
// Note: The source we're casting from must contain only elements of the same type. static void Sample_Cast_Linq() { List<string> vegetables = new List<string> { "Cucumber", "Tomato", "Broccoli" }; var result = from v in vegetables.Cast<string>() select v; Debug.WriteLine("List of vegetables casted to a simple string array:"); foreach (string vegetable in result) Debug.WriteLine(vegetable); }Output:
List of vegetables casted to a simple string array: Cucumber Tomato Broccoli
' Note: The source we're casting from must contain only elements of the same type. Private Shared Sub Sample_Cast_Linq() Dim vegetables As New List(Of String)() From { _ "Cucumber", _ "Tomato", _ "Broccoli" _ } Dim result = From v In vegetables.Cast(Of String)() Select v Debug.WriteLine("List of vegetables casted to a simple string array:") For Each vegetable As String In result Debug.WriteLine(vegetable) Next End SubOutput:
List of vegetables casted to a simple string array: Cucumber Tomato Broccoli
// Note: The source we're casting from must contain only elements of the same type. let Sample_Cast_Linq() = let vegetables = ResizeArray<string>() vegetables.Add("Cucumber") vegetables.Add("Tomato") vegetables.Add("Broccoli") let result = query { for v in vegetables.Cast<string>() do select v } Debug.WriteLine(sprintf "List of vegetables casted to a simple string array:") for str in vegetables do Debug.WriteLine(sprintf "%s" str)Output:
List of vegetables casted to a simple string array: Cucumber Tomato Broccoli
// Note: The source we're casting from must contain only elements of the same type. static void Sample_Cast_Lambda() { List<string> vegetables = new List<string> { "Cucumber", "Tomato", "Broccoli" }; var result = vegetables.Cast<string>(); Debug.WriteLine("List of vegetables casted to a simple string array:"); foreach (string vegetable in result) Debug.WriteLine(vegetable); }Output:
List of vegetables casted to a simple string array: Cucumber Tomato Broccoli
' Note: The source we're casting from must contain only elements of the same type. Private Shared Sub Sample_Cast_Lambda() Dim vegetables As New List(Of String)() From { _ "Cucumber", _ "Tomato", _ "Broccoli" _ } Dim result = vegetables.Cast(Of String)() Debug.WriteLine("List of vegetables casted to a simple string array:") For Each vegetable As String In result Debug.WriteLine(vegetable) Next End SubOutput:
List of vegetables casted to a simple string array: Cucumber Tomato Broccoli
// Note: The source we're casting from must contain only elements of the same type. let Sample_Cast_Lambda() = let vegetables = ResizeArray<string>() vegetables.Add("Cucumber") vegetables.Add("Tomato") vegetables.Add("Broccoli") let result = vegetables.Cast<string>(); Debug.WriteLine(sprintf "List of vegetables casted to a simple string array:") for str in vegetables do Debug.WriteLine(sprintf "%s" str)Output:
List of vegetables casted to a simple string array: Cucumber Tomato Broccoli