C# 中 Write() 和 WriteLine() 方法有什麼區別?


Write() 和 WriteLine() 方法之間的區別基於新行字元。

Write() 方法會顯示輸出,但不會提供新行字元。

WriteLine() 方法會顯示輸出,並在字串末尾提供一個新行字元,從而為下一輸出設定新行。

讓我們看一個例子來了解 Write() 和 WriteLine() 方法之間的區別 −

示例

 即時演示

using System;
class Program {
   static void Main() {
      Console.Write("One");
      Console.Write("Two");

      // this will set a new line for the next output
      Console.WriteLine("Three");
      Console.WriteLine("Four");
   }
}

輸出

OneTwoThree
Four

更新日期: 2020 年 6 月 22 日

5K+ 瀏覽

開啟你的 職業生涯

透過完成課程和考試獲得認證

開始學習
廣告
© . All rights reserved.