匿名委托(方法) 以 ThreadStart 为例


REF:http://baike.baidu.com/view/2761370.htm?fr=aladdin
 
不使用 匿名方法:
static void Main(string[] args)
{
Thread thread = new Thread(new ThreadStart(Run));
// 或 Thread thread = new Thread(Run); // c# 2.0 或以后版本支持
thread.Start();
}
static void Run()
{
// 要运行的代码 ...
}
使用 匿名方法
static void Main(string[] args)
{
Thread thread = new Thread(delegate()
{
// 要运行的代码
});
// 或 Thread thread = new Thread(new ThreadStart(delegate()
//{
// // 要运行的代码
//}));
thread.Start();
}
使用Lambda  表达式
static void Main(string[] args)
{
Thread thread = new Thread(() =>
{
// 要运行的代码
});
// 或 Thread thread = new Thread(new ThreadStart(() =>
//{
// // 要运行的代码
//}));
thread.Start();
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM