ふらっとC#,C♯,C#(初心者用) Part31 at TECH
[2ch|▼Menu]
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