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

运行结果:

posted @ 2013-11-20 20:55  cnxy  阅读(356)  评论(0编辑  收藏  举报
著作版权归 cnxy.me 所有