Quantifier Operators return the Boolean value (either True or false) if some or all the elements in a sequence satisfy a condition,
Mainly two Quantifiers in linq –
Any-
All
Examples (vb)
“Any” to determine if any of the words in the array contain the substring
Public Sub ExampleAny()
Dim words() = {"believe", "relief", "receipt", "field"}
Dim iAfterE = words.Any(Function(w) w.Contains("ei"))
Console.WriteLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE)
End Sub
Result:
There is a word that contains in the list that contains 'ei': True
“All “to return a grouped a list of products only for categories that have all of their products in stock
Public Sub Quantifier_All_Exam()
Dim products = GetProductList()
Dim productGroups = From p In products _
Group p By p.Category Into Group _
Where (Group.All(Function(p) p.UnitsInStock > 0)) _
Select Category, ProductGroup = Group
ObjectDumper.Write(productGroups, 1)
End Sub
Mainly two Quantifiers in linq –
Any-
All
Examples (vb)
“Any” to determine if any of the words in the array contain the substring
Public Sub ExampleAny()
Dim words() = {"believe", "relief", "receipt", "field"}
Dim iAfterE = words.Any(Function(w) w.Contains("ei"))
Console.WriteLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE)
End Sub
Result:
There is a word that contains in the list that contains 'ei': True
“All “to return a grouped a list of products only for categories that have all of their products in stock
Public Sub Quantifier_All_Exam()
Dim products = GetProductList()
Dim productGroups = From p In products _
Group p By p.Category Into Group _
Where (Group.All(Function(p) p.UnitsInStock > 0)) _
Select Category, ProductGroup = Group
ObjectDumper.Write(productGroups, 1)
End Sub
No comments:
Post a Comment