答案 0 :(得分:1)
您可以像这样使用
public class InjectiveDictionary<T, V> : Dictionary<T, V>
{
public new void Add(T key, V value)
{
if (this.ContainsValue(value))
{
throw new Exception("value already used");
}
base.Add(key, value);
}
public InjectiveDictionary(Dictionary<T, V> dict)
{
foreach (var entry in dict)
{
this.Add(entry.Key, entry.Value);
}
}
public InjectiveDictionary()
{
}
}