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