C#匿名委托和Java匿名局部内部类使用方法示例
时间:2021-01-21 10:56:01|栏目:.NET代码|点击: 次
测试代码
复制代码 代码如下:
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);
}