我有兩個班,第一:傳遞委託從類
public class A
{
public delegate void Function();
public string name;
public Function function;
public A(string name, Function function)
{
this.name = name;
this.function = function;
}
}
而在第二:
public class B
{
public delegate void Function();
List<A> ListA;
// somewhere in function
void F()
{
ListA[i].function();
}
// ---
public void AddA(string name, Function function)
{
ListA.Add(new A(name, function)); // error here
}
}
它拋出這些錯誤:
Error 2 Argument 2: cannot convert from 'App.B.Function' to 'App.A.Function'
Error 1 The best overloaded method match for 'App.A.A(string, App.A.Function)' has some invalid arguments
如何解決這個?
的答案是不夠好..而且還要檢查這個http://www.codeproject.com/Articles/71154/C-Delegates -101-A-Practical-Example –