ForEach メソッドおよび ForEach<T> メソッドは、それぞれ 1 つの Action<T> デリゲートをパラメーターとして受け取ります。 このデリゲートによってカプセル化されたメソッドにより、配列またはリスト内の各要素に対して特定の操作を実行できます。 サンプル using System; using System.Collections.Generic; class Program { static void Main() { List<String> names = new List<String>(); names.Add("Bruce"); names.Add("Alfred"); names.Add("Tim"); names.Add("Richard"); // Display the contents of the list using the Print method. names.ForEach(Print); // 匿名メソッドを利用する names.ForEach(delegate(String name) { Console.WriteLine(name); }); } private static void Print(string s) { Console.WriteLine(s); } } フレッツ光が月額556円~【GMOとくとくBB】 コメント: |