面试题:编写一个多线程,每个线程最多只能输出两个字符,整个程序最终输出"paratara".
Action<string> action =
(str) =>
Console.Write(str);
Task.Factory.StartNew(() => action("pa"))
.ContinueWith(antecendent => action("ra"))
.ContinueWith(antecendent => action("ta"))
.ContinueWith(antecendent=>action("ra"))
.Wait();
可以完美解决你的问题
a niu
同学,分呢
什么分
class Program
{
static void Main(string[] args)
{
Thread t1 = new Thread(() =>
{
Console.Write("pa");
});
Thread t2 = new Thread(() =>
{
Console.Write("ra");
});
t1.Start();
t2.Start();
Console.ReadKey();
}
}