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 次瀏覽

開啟您的職業生涯生涯

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.