【发布时间】:2011-08-18 20:53:19
【问题描述】:
我正在尝试实现与Tuple<T1,T2>.Create<T1,T2>(T1 item1, T2 item2) 类似的方法,但我仍然需要指定类型参数,而 Tuple.Create 会推断它们。
我认为这个定义是正确的。我究竟做错了什么?这是我的代码:
public class KeyValuePair<K, V>
{
public K Key { get; set; }
public V Value { get; set; }
public static KeyValuePair<K, V> Create<K, V>(K key, V value)
{
return new KeyValuePair<K, V> { Key = key, Value = value };
}
}
【问题讨论】: