ふらっとC#,C♯,C#(初心者用) Part31at TECH
ふらっとC#,C♯,C#(初心者用) Part31 - 暇つぶし2ch390:デフォルトの名無しさん
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