Find・FindLast・FindAllメソッドを使って条件に合致するList内の要素を取得する(ラムダ式版) VB10
Imports System
Imports System.Collections.Generic
Class Sample
Shared Sub Main()
Dim list As New List(Of String)(New String() {"Alice", "Bob", "Charlie", "Dave", "Eve"})
' 長さが3である最初の要素
Console.WriteLine("Find: {0}", list.Find(Function(s) s.Length = 3))
' 長さが3である最後の要素
Console.WriteLine("FindLast: {0}", list.FindLast(Function(s) s.Length = 3))
' "e"を含むすべての要素
Dim found As List(Of String) = list.FindAll(Function(s) s.Contains("e"))
Console.Write("FindAll: ")
For Each e As String In found
Console.Write("{0}, ", e)
Next
Console.WriteLine()
End Sub
End Class
実行結果
Find: Bob FindLast: Eve FindAll: Alice, Charlie, Dave, Eve,