有没有像这样编写方法的场景:
public async Task<SomeResult> DoSomethingAsync()
{
// Some synchronous code might or might not be here... //
return await DoAnotherThingAsync();
}
Run Code Online (Sandbox Code Playgroud)
而不是这个:
public Task<SomeResult> DoSomethingAsync()
{
// Some synchronous code might or might not be here... //
return DoAnotherThingAsync();
}
Run Code Online (Sandbox Code Playgroud)
会有意义吗?
为什么return await在可以直接Task<T>从内部DoAnotherThingAsync()调用返回时使用构造?
我return await在很多地方看到代码,我想我应该错过一些东西.但据我了解,在这种情况下不使用async/await关键字并直接返回Task将在功能上等效.为什么要增加附加await层的额外开销?
使用IActionResultWebApi控制器的返回类型而不是您想要返回的实际类型有什么优势或建议?
我见过的大多数示例都返回了IActionResult,但是当我构建我的第一个站点时,我专门使用View Model类作为我的返回类型....现在我觉得我做错了!