08/10/03 20:57:23
>>388
こんなんでどうだろ?
public static class IListExtensions {
public delegate void Fun<T>(T obj, int index);
public static void EachWithIndex<T>(this IList<T> lst, Fun<T> func){
int index = 0;
foreach (T obj in lst){
func(obj, index++);
}
}
}
class Program
{
static void Main(string[] args)
{
string[] strs = { "Foo", "Bar", "Zot" };
strs.EachWithIndex(
(name, index) => { System.Console.WriteLine("{0}: {1}", index, name); }
);
IList<string> lst = new List<string>();
lst.Add("Hoge");
lst.Add("Fuga");
lst.Add("Sugo");
lst.EachWithIndex(
(name, index) => { System.Console.WriteLine("{0}: {1}", index, name); }
);
System.Console.ReadLine();
}
}