一、以下代碼共創建了幾個Task?
[csharp]
var tasks = Enumerable.Range(1, 1).Select(i => new Task(() =>
{
Debug.WriteLine(i);
})).ToList();
var ts1 = tasks.ToList();
var ts2 = tasks.ToArray();
二、找錯誤:
[csharp]
var tasks = Enumerable.Range(1, 1).Select(i => new Task(() =>
{
Debug.WriteLine(i);
}));
tasks.ToList().ForEach(t => t.Start());
Task.WaitAll(tasks.ToArray());
Console.WriteLine("完畢");
三、以下代碼在vs2010中的執行結果是?
[csharp] www.2cto.com
var sequence = Enumerable.Range(1, 2).ToList();
sequence.Select(i => new Action(() => Debug.WriteLine(i))).ToList().ForEach(a => a());
Action prints = null;
foreach (var i in sequence)
{
prints += () => Debug.WriteLine(i);
}
prints();