当我编写以下代码时:
Task<string> task = Task.Factory.StartNew<string>(() => "first task")
.ContinueWith(t =>
{
Console.WriteLine(t.Result);
Console.WriteLine("second task");
});
那是错的!
然后我把它改成这样:
var task = Task.Factory.StartNew<string>(() => "first task")
.ContinueWith(t =>
{
Console.WriteLine(t.Result);
Console.WriteLine("second task");
});
然后一切正常!
为什么?
“Task task”和“var task”有什么区别?</p>