機能
条件を満たす最後の要素を返します。
要素が1件もない場合はエラーとなります。
オーバーロード
Lastには2つのオーバーロードがあります。
- 引数なし
- 条件
サンプル
1 2 3 4 5 6 7 8 9 10 11 12 |
int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54, 83, 23, 87, 67, 12, 19 }; int last = numbers.Last(); Console.WriteLine(last); /* This code produces the following output: 19 */ |
1 2 3 4 5 6 7 8 9 10 11 12 |
int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54, 83, 23, 87, 67, 12, 19 }; int last = numbers.Last(num => num > 80); Console.WriteLine(last); /* This code produces the following output: 87 */ |