ふらっとC#,C♯,C#(初心者用) Part26at TECH
ふらっとC#,C♯,C#(初心者用) Part26 - 暇つぶし2ch381:デフォルトの名無しさん
08/03/30 23:32:42
>>358
IList<>とIDictionary<>のインデクサの汎用ラッパー作ってみた

public static class Indexer {
public static DictionaryIndexer<TKey, TValue> GetIndexer<TKey, TValue>(this IDictionary<TKey, TValue> dict) { return new DictionaryIndexer<TKey, TValue>(dict); }
public static ListIndexer<T> GetIndexer<T>(this IList<T> list) { return new ListIndexer<T>(list); }
}

public sealed class DictionaryIndexer<TKey, TValue> {
private IDictionary<TKey, TValue> dict;
internal DictionaryIndexer(IDictionary<TKey, TValue> dict) { this.dict = dict; }
public TValue this[TKey key] { get { return dict[key]; } set { dict[key] = value; } }
}

public sealed class ListIndexer<T> {
private IList<T> list;
internal ListIndexer(IList<T> list) { this.list = list; }
public T this[int index] { get { return list[index]; } set { list[index] = value; } }
}




次ページ
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch