All with Function
Imports System
Imports System.Linq
Imports System.Collections.Generic
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Structure Person
Public LastName As String
Public Pets() As Pet
End Structure
Public Class Example
Public Shared Sub Main()
Dim people As New List(Of Person)(New Person() _
{New Person With {.LastName = "A", .Pets = New Pet() {New Pet With {.Name = "A1", .Age = 10}, _
New Pet With {.Name = "A2", .Age = 14}, _
New Pet With {.Name = "A3", .Age = 6}}}, _
New Person With {.LastName = "B", .Pets = New Pet() {New Pet With {.Name = "B1", .Age = 1}}}, _
New Person With {.LastName = "C", .Pets = New Pet() {New Pet With {.Name = "C1", .Age = 8}}}, _
New Person With {.LastName = "D", .Pets = New Pet() {New Pet With {.Name = "D1", .Age = 2}, _
New Pet With {.Name = "D2", .Age = 13}}}})
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
End Sub
End Class
Related examples in the same category