C#匿名委托和Java匿名局部内部类使用方法示例
测试代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpStudy
{
class Program
{
static void Main(string[] args)
{
int i = 0;
Action action1 = () =>
{
System.Console.WriteLine(i);
};
i++;
Action action2 = () =>
{
System.Console.WriteLine(i);
};
i++;
action1();
action2();
}
}
}
private static void Main(string[] args)
{
<>c__DisplayClass2 CS$<>8__locals3 = new <>c__DisplayClass2();
CS$<>8__locals3.i = 0;
Action action1 = new Action(CS$<>8__locals3.<Main>b__0);
CS$<>8__locals3.i++;
Action action2 = new Action(CS$<>8__locals3.<Main>b__1);
CS$<>8__locals3.i++;
action1();
action2();
}
public void <Main>b__0()
{
Console.WriteLine(this.i);
}
public void <Main>b__1()
{
Console.WriteLine(this.i);
}
最新评论