可能重复:
Compilation fails if delegate definitions is put in another project?
使用.NET 3.5 SP1和Visual Studio 2008
项目A和B,两个类库,A使用B. 在项目B中,我有以下内容:
public delegate void MyDelegate(object o1, EventArgs o2);
public delegate T MyUberDelegate<T>(MyDelegate myDelegate);
public class MyTestClass
{
private MyUberDelegate<EventHandler> uberDelegate;
public MyTestClass()
{
uberDelegate = h => (s, e) => h(s, e);
}
}
编译,没问题。 (uberDelegate返回一个调用MyDelegate的EventHandler)
如果我将MyTestClass复制到项目A,我会收到以下编译错误:
Error 1 Cannot convert lambda expression to delegate type 'MyUberDelegate<System.EventHandler>' because some of the return types in the block are not implicitly convertible to the delegate return type
Error 2 Delegate 'MyDelegate' does not take '2' arguments
如果我改变MyTestClass以包含MyDelegate类型的字段,它确实有效:
public class MyTestClass
{
private MyUberDelegate<EventHandler> uberDelegate;
private MyDelegate myDelegate;
public MyTestClass()
{
uberDelegate = h => (s, e) => h(s, e);
}
}
为什么吗
编辑:Compilation fails if delegate definitions is put in another project?
的副本