Console.In.Peek() returns -1 on enter

后端 未结 2 991
野性不改
野性不改 2021-01-25 17:41

I would have expected the following C# program to only print \"EOF!\" once I hit \"Ctrl-Z\" in the console. Instead, the program finishes as soon as I hit Enter:



        
2条回答
  •  难免孤独
    2021-01-25 18:09

    Console.In.Read() returns -1 on EOF, So you can do this:

    int c;
    while((c = Console.In.Read()) != -1)
    Console.Out.Write((char)c);
    

提交回复
热议问题