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

2017-12-25 15:32:30 浏览数 (1)

代码语言:javascript复制
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();
        }
    }
}

运行结果:

0 人点赞