// Create a handler for a click event
button
{ System
// Create a delegate instance
delegate void Del(int x);
// Instantiate the delegate using an anonymous method
Del d = delegate(int k) { /*
例如
void StartThread()
{
System
(delegate()
{
System
System
});
t
}
如果局部變量和參數的范圍包含匿名方法聲明
int n =
Del d = delegate() { System
匿名方法不能訪問外部范圍的 ref 或 out 參數
在 anonymous
// Declare a delegate
delegate void Printer(string s);
class TestClass
{
static void Main()
{
// Instatiate the delegate type using an anonymous method:
Printer p = delegate(string j)
{
System
};
// Results from the anonymous delegate call:
p(
// The delegate instantiation using a named method
p = new Printer(TestClass
// Results from the old style delegate call:
p(
}
// The method associated with the named delegate:
static void DoWork(string k)
{
System
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12025.html