我的代碼有什麼問題?無法將類型IAsyncOperation <StorageFile>隱式轉換爲StorageFile
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker FilePicker = new FileOpenPicker();
FilePicker.FileTypeFilter.Add(".exe");
FilePicker.ViewMode = PickerViewMode.List;
FilePicker.SuggestedStartLocation = PickerLocationId.Desktop;
// IF I PUT AWAIT HERE V I GET ANOTHER ERROR¹
StorageFile file = FilePicker.PickSingleFileAsync();
if (file != null)
{
AppPath.Text = file.Name;
}
else
{
AppPath.Text = "";
}
}
它給我這個錯誤:
Cannot implicitly convert type 'Windows.Foundation.IAsyncOperation' to 'Windows.Storage.StorageFile'
如果我加入 '等待',就像評論的代碼,我收到以下錯誤:
¹ The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.
代碼源here
現在我明白了,非常感謝!我開始學習C#,而這個異步/等待的東西對我來說真的很新鮮。 您的幫助非常感謝! – gabrieljcs 2013-05-12 22:16:58