Why return type of async must be void, Task or Task

前端 未结 2 1508
执笔经年
执笔经年 2021-01-01 23:48

I am trying get my hands dirty with async CTP and I noticed that the compiler complains about the async return type. What is the problem with other types?

A simple d

2条回答
  •  情书的邮戳
    2021-01-02 00:22

    Because a Task is a "future" - a value that will be coming along later. A string[] is something you have right now.

    Similarly, Task is an operation that will complete (either successfully or with an error) sometime in the future.

    void is something of a special case; it represents a top-level operation in the Async CTP.

    If you're wondering why the Task isn't automatically inferred, this was considered but rejected by the Async CTP team. Their rationale is here, and this thread also covers it.

提交回复
热议问题