またConvertAllメソッドは、型変換だけでなくすべての要素に同じ処理を施した結果を取得するといった方法にも使えます。
ConvertAllメソッドを使ってList内のすべての文字列をリバースした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"})
' list内のすべての要素を変換する
Dim reversedList As List(Of String) = list.ConvertAll(Function(s)
' 文字列(list内の各要素)をリバースする
Dim chars() As Char = s.ToCharArray()
Array.Reverse(chars)
Return New String(chars)
End Function)
For Each e As String In reversedList
Console.WriteLine(e)
Next
End Sub
End Class
実行結果
ecilA boB eilrahC evaD evE