线程、委托、lambda运算符的简单示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace ConsoleApplication11 { class Program { public delegate void TestDeleagte(string temp); static void Main(string[] args) { Thread t = new Thread(() => { TestDeleagte test = (string temp) => { Console.WriteLine("调用了线程test的委托,其参数为:" + temp); Console.WriteLine("请注意lambda运算符“=>”的使用"); }; test("这是测试,参数为本行字符串"); }); Console.WriteLine("线程状态:{0}", t.ThreadState.ToString());; t.Start(); Console.WriteLine("线程状态:{0}",t.ThreadState.ToString()); t.Join(); Console.WriteLine("线程状态:{0}:", t.ThreadState.ToString()); Console.ReadKey(); } } }
运行结果:
作者:CNXY Github:https://www.github.com/cnxy 出处:http://cnxy.me 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 如果文中有什么错误,欢迎指出,谢谢! |