Why async / await allows for implicit conversion from a List to IEnumerable?

前端 未结 3 1761
野趣味
野趣味 2021-02-12 03:47

I\'ve just been playing around with async/await and found out something interesting. Take a look at the examples below:

// 1) ok - obvious
public Task

        
3条回答
  •  隐瞒了意图╮
    2021-02-12 04:03

    Just think about your types. Task is not variant, so it's not convertible to Task, even if T : U.

    However, if t is Task, then the type of await t is T, and T can be converted to U if T : U.

提交回复
热议问题