【发布时间】:2012-10-20 23:28:36
【问题描述】:
我们有这个方法:
async Task<int> AccessTheWebAsync()
{
HttpClient client = new HttpClient();
Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com");
// You can do work here that doesn't rely on the string from GetStringAsync.
DoIndependentWork();
string urlContents = await getStringTask;
//The thing is that this returns an int to a method that has a return type of Task<int>
return urlContents.Length;
}
Task<int> 和 int 之间是否发生隐式转换?如果不是,那么发生了什么?它是如何实现的?
【问题讨论】:
-
Keep reading。我假设编译器会根据
async关键字来处理这个问题。 -
@Freeman,看看这个很棒的解释:stackoverflow.com/a/4047607/280758
标签: c# .net asynchronous .net-4.5 c#-5.0