我们有这种方法:
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
?如果没有,那是怎么回事?如何实施工作?
@Freeman,请看下面这个很好的解释:stackoverflow.com/a/4047607/280758
—
qehgt 2012年
async
关键字来处理该问题。