Select with Function
Imports System
Imports System.Linq
Imports System.Collections.Generic
Structure Pet
Public Name As String
Public Age As Integer
End Structure
Public Class Example
Public Shared Sub Main()
Dim cats() As Pet = {New Pet With {.Name = "A", .Age = 8}, _
New Pet With {.Name = "B", .Age = 4}, _
New Pet With {.Name = "C", .Age = 1}}
Dim dogs() As Pet = {New Pet With {.Name = "D", .Age = 3}, _
New Pet With {.Name = "E", .Age = 14}, _
New Pet With {.Name = "F", .Age = 9}}
Dim animals() As IEnumerable(Of Pet) = {cats, dogs}
Dim query As IEnumerable(Of String) = (animals.SelectMany(Function(pets) pets.Select(Function(pet) pet.Name)))
For Each name As String In query
Console.WriteLine(name)
Next
End Sub
End Class
Related examples in the same category