ふらっとC#,C♯,C#(初心者用) Part31
at TECH
390:デフォルトの名無しさん
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();
}
}
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
5377日前に更新/215 KB
担当:undef