機能
IEnumerable<T> から List<T> を作成します。
オーバーロード
ToListにはオーバーロードはありません。
引数
なし
サンプル
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
string[] fruits = { "apple", "passionfruit", "banana", "mango", "orange", "blueberry", "grape", "strawberry" }; List<int> lengths = fruits.Select(fruit => fruit.Length).ToList(); foreach (int length in lengths) { Console.WriteLine(length); } /* This code produces the following output: 5 12 6 5 6 9 5 10 */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
' Create an array of strings. Dim fruits() As String = {"apple", "passionfruit", "banana", "mango", "orange", "blueberry", "grape", "strawberry"} ' Project the length of each string and ' put the length values into a List object. Dim lengths As List(Of Integer) = fruits _ .Select(Function(fruit) fruit.Length) _ .ToList() ' Display the results. Dim output As New System.Text.StringBuilder For Each length As Integer In lengths output.AppendLine(length) Next MsgBox(output.ToString()) ' This code produces the following output: ' ' 5 ' 12 ' 6 ' 5 ' 6 ' 9 ' 5 ' 10 |
関連
| AsEnumerable | ToDictionary | ToList | ToArray | ToLookup |