最近初学C#,写了下面的程序,有个小问题不知道怎么修改,请大家帮忙看看
namespace ConsoleApplication18
{
public delegate void Mydelegate()
where T : struct
where U : class, new();
class A
{
public void Show() { Console.WriteLine("Welcome"); }
}
class B
{
public static void F(int aa, A obj) { Console.WriteLine(aa.ToString()); }
public void G(decimal dd, A obj) { Console.WriteLine(string.Format("{0:C3}", dd)); }
}
class Program
{
static void Main(string[] args)
{
Mydelegate<int, A> mt = new Mydelegate<int, A>(B.F); //这行有错
Console.ReadKey();
}
}
}
//错误提示信息: 错误 1 “F”的重载均与委托“ConsoleApplication18.Mydelegate”不匹配 c:\users\zhangye-1\documents\visual studio 2012\Projects\ConsoleApplication18\ConsoleApplication18\Program.cs 28 37 ConsoleApplication18
要不mydelegate定义上加2个参数,要么f定义去掉参数,总之得一致。
要不mydelegate定义上加2个参数,要么f定义去掉参数,总之得一致。