class Program
{
static void Main(string[] args)
{
//Action a = delegate ()
// {
// Console.WriteLine("匿名函数逻辑");
// };
//a();
//Action<int, string> bs = delegate (int a,string b)
// {
// Console.WriteLine(a);
// Console.WriteLine(b);
// };
//bs(100, "hello");
Test t = new Test();
Action ac = delegate ()
{
Console.WriteLine("随参数传入的匿名函数逻辑");
};
t.DoSomething(100, ac);
t.DoSomething(100, delegate () { Console.WriteLine("随参数传入的匿名函数逻辑"); });
Action ac2 = t.GetFun();
ac2();
t.GetFun()();
}
}
class Test
{
public Action action;
public void DoSomething(int a,Action fun)
{
Console.WriteLine(a);
fun();
}
public Action GetFun()
{
return TestTTTT;
}
public void TestTTTT()
{
}
}
namespace ConsoleApp22
{
class Program
{
static Func<int,int> TestFun(int i)
{
return delegate (int v)
{
return i * v;
};
}
static void Main(string[] args)
{
Func<int, int> fun = TestFun(2);
Console.WriteLine(fun(3));
}
}
}