我想使用 Lambda 表达式,但是当我尝试调用它时,会在下面注释的行中出现错误。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleAppTestDelegate2
{
public delegate string MyDelegate (int a);
public class ClassRunDelegate
{
public void RunDelegate(MyDelegate a, int b)
{
Console.WriteLine(a(b));
}
}
public class MyHelp
{
public string test(int a)
{
a++;
return a.ToString();
}
}
class Program
{
static void Main(string[] args)
{
MyHelp fhelp = new MyHelp();
//
MyDelegate fdelegate = new MyDelegate(fhelp.test);
ClassRunDelegate cc = new ClassRunDelegate();
cc.RunDelegate(fdelegate, 10);
///
cc.RunDelegate((a, b) => { Console.WriteLine("test"); });// get error this line
Console.ReadLine();
}
}
}