HashSetの拡張メソッドAddRangeを作成しようとしているので、次のようなことができます。
var list = new List<Item>{ new Item(), new Item(), new Item() };
var hashset = new HashSet<Item>();
hashset.AddRange(list);
これは私がこれまでに持っているものです:
public static void AddRange<T>(this ICollection<T> collection, List<T> list)
{
foreach (var item in list)
{
collection.Add(item);
}
}
問題は、AddRangeを使用しようとすると、次のコンパイラエラーが発生することです。
The type arguments for method 'AddRange<T>(System.Collections.Generic.ICollection<T>, System.Collections.Generic.List<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
言い換えれば、私は代わりにこれを使用することになります:
hashset.AddRange<Item>(list);
私はここで何が間違っているのですか?