转换Task< String>到Windows 8应用程序的字符串
本文关键字:应用程序 字符串 Windows Task String 转换 | 更新日期: 2023-09-27 18:04:00
我在写一个Windows 8应用程序。我有一个代码:
public async Task<string> readweb()
{
var uri = new Uri(@"http://stackoverflow.com/");
var httpClient = new HttpClient();
var data = await httpClient.GetStringAsync(uri);
string text = data;
return text;
}
我想通过string data = readweb();
获得web数据,但它错误"无法将任务转换为字符串"。帮帮我!谢谢!
这样做,
public async Task<string> readweb()
{
var uri = new Uri(@"http://stackoverflow.com/");
var httpClient = new HttpClient();
var data = await httpClient.GetStringAsync(uri);
string text = data;
return text;
}
private async void Something()
{
var data = await readweb();
}