Why does a single line app with System.Console.WriteLine give me a syntax error?

前端 未结 2 809
春和景丽
春和景丽 2021-01-25 19:23

I decided to have a go at building Windows Metro style apps with the Windows Developer Preview again, after multiple frustrating experiences.

So I fire up Visual Studio

相关标签:
2条回答
  • 2021-01-25 19:59

    Because Metro applications use a subset of the .Net Framework API. In this version System.Console and System.IO.File do not exist.

    From MSDN, "Replace System.IO.File.ReadAllText method with a method that uses the asynchronous I/O members; for example:"

    public static async Task<string> ReadAllText(StorageFile file)
    {
        IInputStream inputStream = await file.OpenForReadAsync();
        using (Stream stream = inputStream.AsStream())
        using (StreamReader reader = new StreamReader(stream))
        {
            return await Task.Run(() => reader.ReadToEnd());
        }
    }
    
    0 讨论(0)
  • 2021-01-25 20:22

    Windows 8 Metro Apps don't have a console (as the console in a graphical environment doesn't make sense), but you can get some of the functionality of the console with third party libraries like Console Class for Metro Apps

    0 讨论(0)
提交回复
热议问题