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


Read()

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

int a = Console.Read()
Console.WriteLine(a);

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 年 6 月 22 日

627 次瀏覽

開啟你的 職業生涯

完成課程認證

開始學習
廣告