C# 中 Read()、ReadKey() 和 ReadLine() 方法之間有什麼區別?


Read()

Read() 從標準輸入流中讀取下一個字元。如果在控制檯上按了某個鍵,就會關閉。

int az = Console.Read()
Console.WriteLine(z);

ReadKey()

僅從標準輸入流中讀取單個字元。

ReadLine()

從標準輸入流中讀取下一行字元。

示例

 即時演示

using System;
class Program {
   static void Main() {

      int x = 10;
      Console.WriteLine(x);
      Console.Write("
Press any key to continue... ");       Console.ReadLine();    } }

輸出

10

Press any key to continue...

更新於: 2020-06-22

1 千 + 瀏覽量

啟動您的 職業

完成課程,獲得認證

開始
廣告
© . All rights reserved.