gpt4 book ai didi

c# - Web Api 方法返回任务的缺点

转载 作者:太空狗 更新时间:2023-10-30 01:03:56 25 4
gpt4 key购买 nike

为什么返回一个Task<T>的做法来自 Web Api 方法不是默认方法,而是在您在 Visual Studio 中创建新的 Web Api Controller 时获得的方法中?

这样做有什么缺点吗?

public class MyController : ApiController
{
public Task<string> Boo()
{
return Task.Factory.StartNew(() =>
{
return "Boo";
});
}
}

最佳答案

Are there any disadvantages to doing this?

是的,您无缘无故地降低了代码的可读性、更长的时间和性能。我看不到这样做有任何优势

关于c# - Web Api 方法返回任务的缺点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25663711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com