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

时间:2024-04-23 19:05:06
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运算符的简单示例