Exists・TrueForAllメソッドを使って条件に合致する要素が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"})
' 長さが5以上の要素が存在するかどうか
Console.WriteLine("Exists: {0}", list.Exists(Function(s) 5 <= s.Length))
' すべての要素が"e"で終わるかどうか
Console.WriteLine("TrueForAll: {0}", list.TrueForAll(Function(s) s.EndsWith("e")))
' すべての要素の長さが10未満かどうか
Console.WriteLine("TrueForAll: {0}", list.TrueForAll(Function(s) s.Length < 10))
End Sub
End Class
実行結果
FindLast: Eve TrueForAll: False TrueForAll: True