C# 线程传参数 利用lambda表达式

2018-01-05  本文已影响584人  我是Mr小赵先生

using System;
using System.Threading;

namespace ThreadWithParameters
{
class Program
{
static void Main(string[] args)
{
string hello = "hello world";

        //如果写成Thread thread = new Thread(ThreadMainWithParameters(hello));这种形式,编译时就会报错
        Thread thread = new Thread(() => ThreadMainWithParameters(hello));
        thread.Start();

        Console.Read();
    }

    static void ThreadMainWithParameters(string str)
    {
         Console.WriteLine("Running in a thread,received: {0}", str);
    }
}

}

上一篇 下一篇

猜你喜欢

热点阅读