线程、委托、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();
}
}
}

运行结果:

线程、委托、lambda运算符的简单示例

上一篇:Linux查看监听端口的脚本测试


下一篇:pytorch 解决gpu训练只占一块卡