本文整理汇总了VB.NET中System.Linq.Enumerable.Any方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Enumerable.Any方法的具体用法?VB.NET Enumerable.Any怎么用?VB.NET Enumerable.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Enumerable.Any方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: List
' Create a list of Integers.
Dim numbers As New List(Of Integer)(New Integer() {1, 2})
' Determine if the list contains any items.
Dim hasElements As Boolean = numbers.Any()
' Display the output.
Dim text As String = IIf(hasElements, "not ", "")
Console.WriteLine($"The list is {text}empty.")
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:9,代码来源:Enumerable.Any 输出:
The list is not empty.
示例2: AnyEx2
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 AnyEx2()
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 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 a non-empty Pet array.
Dim names = From person In people
Where person.Pets.Any()
Select person.LastName
For Each name As String In names
Console.WriteLine(name)
Next
' This code produces the following output:
'
' Haas
' Fakhouri
' Philips
End Sub
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:40,代码来源:Enumerable.Any
示例3: List
Structure Pet
Public Name As String
Public Age As Integer
Public Vaccinated As Boolean
End Structure
Shared Sub AnyEx3()
' Create a list of Pets
Dim pets As New List(Of Pet)(New Pet() _
{New Pet With {.Name = "Barley", .Age = 8, .Vaccinated = True},
New Pet With {.Name = "Boots", .Age = 4, .Vaccinated = False},
New Pet With {.Name = "Whiskers", .Age = 1, .Vaccinated = False}})
' Determine whether any pets over age 1 are also unvaccinated.
Dim unvaccinated As Boolean =
pets.Any(Function(pet) pet.Age > 1 And pet.Vaccinated = False)
' Display the output.
Dim text As String = IIf(unvaccinated, "are", "are not")
Console.WriteLine($"There {text} unvaccinated animals over age 1.")
End Sub
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:21,代码来源:Enumerable.Any 输出:
There are unvaccinated animals over age 1.
注:本文中的System.Linq.Enumerable.Any方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论