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
Any: Checks if any elements in a collection satisifies a specified condition.
Any: Checks if any elements in a collection satisifies a specified condition. |
Any: Checks if any elements in a collection satisifies a specified condition. |
This Query Expression sample checks whether any names in array start with the letter 'B'. |
This Query Expression sample checks whether any names in array start with the letter 'B'. |
// A Query Expression cannot be constructed for Any() in C#. // Consider using a Lambda Expression instead.
Private Shared Sub Sample_Any_Linq() Dim names As String() = {"Bob", "Ned", "Amy", "Bill"} Dim result = Aggregate n In names Into Any() Debug.WriteLine("Does any of the names start with the letter 'B':") Debug.WriteLine(result) End SubOutput:
Does any of the names start with the letter 'B': True
// There is no Any() for Query Expressions in F#, but it has the similar "exists". let Sample_Any_Linq() = let names = [|"Bob"; "Ned"; "Amy"; "Bill"|] let result = query { for n in names do exists (n.StartsWith "B") } Debug.WriteLine(sprintf "Does any of the names start with the letter 'B':") Debug.WriteLine(result);Output:
Does any of the names start with the letter 'B': True
static void Sample_Any_Lambda() { string[] names = { "Bob", "Ned", "Amy", "Bill" }; var result = names.Any(n => n.StartsWith("B")); Debug.WriteLine("Does any of the names start with the letter 'B':"); Debug.WriteLine(result); }Output:
Does any of the names start with the letter 'B': True
Private Shared Sub Sample_Any_Lambda() Dim names As String() = {"Bob", "Ned", "Amy", "Bill"} Dim result = names.Any(Function(n) n.StartsWith("B")) Debug.WriteLine("Does any of the names start with the letter 'B':") Debug.WriteLine(result) End SubOutput:
Does any of the names start with the letter 'B': True
let Sample_Any_Lambda() = let names = [|"Bob"; "Ned"; "Amy"; "Bill"|] let result = names.Any(fun n -> n.StartsWith "B") Debug.WriteLine(sprintf "Does any of the names start with the letter 'B':") Debug.WriteLine(result);Output:
Does any of the names start with the letter 'B': True