4
我想创建一个方法是这样的:C#委托词典添加
private static void AddOrAppend<K>(this Dictionary<K, MulticastDelegate> firstList, K key, MulticastDelegate newFunc)
{
if (!firstList.ContainsKey(key))
{
firstList.Add(key, newFunc);
}
else
{
firstList[key] += newFunc; // this line fails
}
}
但这种失败,因为它说,你不能添加多路广播委托。有什么我失踪?我认为委托关键字只是从MulticastDelegate继承的类的简写。
或者你可以在.NET 4.0中使用'ConcurrentDictionary' ... – 2010-07-26 19:52:54
@Steven - 我不知道这是怎么解决的问题? – 2010-07-26 20:01:25
@Marc:这不是问题的解决方案,它是通过不重新发明轮子完全避免它的一种方法。具体来说,他试图创建的功能类型已经可用:http://msdn.microsoft.com/en-us/library/ee378675.aspx – 2010-07-26 20:29:16