C#匿名委托和Java匿名局部内部类使用方法示例
程序员文章站
2024-02-21 21:51:58
测试代码
复制代码 代码如下:using system;using system.collections.generic;using system.linq;using...
测试代码
复制代码 代码如下:
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);
}
上一篇: MySQL多表之间字段的匹配实现代码