无法将类型'Windows.Storage.StorageFile'隐式转换为'bool'

时间:2015-03-04 07:40:54

标签: c# windows-phone-8.1

当我返回" FileExists#34;这段代码中的变量我收到错误..

public static async Task<bool> FileExistsForWp8(string filename)
    {
        StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;            
        try
        {
            StorageFile FileExists = await folder.GetFileAsync(filename);
            return FileExists;
        }
        catch (Exception ex)
        {
            return FileExists;
        }
    }

1 个答案:

答案 0 :(得分:1)

GetFileAsync会返回StorageFile

你的意思:

public static async Task<bool> FileExistsForWp8(string filename)
{
    StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;  
    try
    {
       StorageFile File = await folder.GetFileAsync(filename);
       return true;
    }
    catch
    {
        return false;
    }
}