在Jumpstart视频中(构建适用于Windows Phone 8 Jumpstart的应用) 他们展示了给我错误的示例代码: “异步方法的返回类型必须是无效的,T的任务或任务
这是示例代码:
//open
private async string loadStringAsync()
{
string theData = string.Empty;
//Get a reference to the local folder
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile storageFile = await localFolder.GetFileAsync("MyFile.store");
//Open it and read it
Stream readStream = await storageFile.OpenStreamForReadAsync();
using (StreamReader reader = new StreamReader(readStream))
{
theData = await reader.ReadToEndAsync();
}
return theData;
}
我想它需要一个简单的修复,但由于我是编程的新手并且该特定视频的注释被禁用,我不知道如何...
答案 0 :(得分:0)
var a = loadStringAsync();
private async Task<string> loadStringAsync()
{
string theData = string.Empty;
//Get a reference to the local folder
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile storageFile = await localFolder.GetFileAsync("MyFile.store");
//Open it and read it
Stream readStream = await storageFile.OpenStreamForReadAsync();
using (StreamReader reader = new StreamReader(readStream))
{
theData = await reader.ReadToEndAsync();
}
return theData;
}