为什么返回一个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/