1
我努力为其值中包含List的字典定义扩展方法。如何在TValue中使用IList创建IDictionary的扩展方法?
我已经做到了这一点:
public static bool MyExtensionMethod<TKey, TValue, K>(this IDictionary<TKey, TValue> first, IDictionary<TKey, TValue> second) where TValue : IList<K>
{
//My code...
}
要使用它,我有这个类:
public class A
{
public Dictionary<int, List<B>> MyPropertyA { get; set; }
}
public class B
{
public string MyPropertyB { get; set; }
}
但是,当我这样做:
var a1 = new A();
var a2 = new A();
var a = a1.MyPropertyA.MyExtensionMethod(a2.MyPropertyA)
我得到这个错误'方法的类型参数'...'不能从用法'
我该如何定义方法或调用它?提前致谢!!
这工作!我会看看查找类。非常感谢。 – joacoleza