本文整理匯總了VB.NET中System.Linq.Enumerable.All<TSource>方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Enumerable.All<TSource>方法的具體用法?VB.NET Enumerable.All<TSource>怎麽用?VB.NET Enumerable.All<TSource>使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了Enumerable.All<TSource>方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: AllEx
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub AllEx()
' Create an array of Pets.
Dim pets() As Pet =
{New Pet With {.Name = "Barley", .Age = 2},
New Pet With {.Name = "Boots", .Age = 4},
New Pet With {.Name = "Whiskers", .Age = 7}}
' Determine whether all pet names in the array start with "B".
Dim allNames As Boolean =
pets.All(Function(ByVal pet) pet.Name.StartsWith("B"))
' Display the output.
Dim text As String = IIf(allNames, "All", "Not all")
Console.WriteLine($"{text} pet names start with 'B'.")
End Sub
輸出:
Not all pet names start with 'B'.
示例2: AllEx2
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Structure Person
Public LastName As String
Public Pets() As Pet
End Structure
Sub AllEx2()
Dim people As New List(Of Person)(New Person() _
{New Person With {.LastName = "Haas",
.Pets = New Pet() {New Pet With {.Name = "Barley", .Age = 10},
New Pet With {.Name = "Boots", .Age = 14},
New Pet With {.Name = "Whiskers", .Age = 6}}},
New Person With {.LastName = "Fakhouri",
.Pets = New Pet() {New Pet With {.Name = "Snowball", .Age = 1}}},
New Person With {.LastName = "Antebi",
.Pets = New Pet() {New Pet With {.Name = "Belle", .Age = 8}}},
New Person With {.LastName = "Philips",
.Pets = New Pet() {New Pet With {.Name = "Sweetie", .Age = 2},
New Pet With {.Name = "Rover", .Age = 13}}}})
' Determine which people have pets that are all older than 5.
Dim names = From person In people
Where person.Pets.All(Function(pet) pet.Age > 5)
Select person.LastName
For Each name As String In names
Console.WriteLine(name)
Next
' This code produces the following output:
'
' Haas
' Antebi
End Sub