现在的位置: 首页 > 综合 > 正文

c# 匿名方法的小例子

2012年11月12日 ⁄ 综合 ⁄ 共 426字 ⁄ 字号 评论关闭

复制代码 代码如下:
// 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();
}

抱歉!评论已关闭.