C# Task which returns a value

后端 未结 2 1858
既然无缘
既然无缘 2021-01-18 08:30

I\'m trying to run a function in a task but I\'m doing something wrong. Heres an example:

var t = Task.Factory.StartNew(() => GenerateResult(2)         


        
2条回答
  •  难免孤独
    2021-01-18 08:35

    You are printing the task object that you created. For result, see .Result property:

    Console.WriteLine(t.Result);

提交回复
热议问题