c# 匿名方法的小例子
程序员文章站
2023-12-10 19:04:16
复制代码 代码如下:// create a handler for a click event.button1.click += delegate(system.objec...
复制代码 代码如下:
// create a handler for a click event.
button1.click += delegate(system.object o, system.eventargs e)
{ system.windows.forms.messagebox.show("click!"); };
// create a delegate.
delegate void del(int x);
// instantiate the delegate using an anonymous method.
del d = delegate(int k) { /* ... */ };
void startthread()
{
system.threading.thread t1 = new system.threading.thread
(delegate()
{
system.console.write("hello, ");
system.console.writeline("world!");
});
t1.start();
}