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


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...

更新於: 22-06-2020

1K+ 次瀏覽

開啟你的職業 生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.