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-06-22

5千+ 次瀏覽

職業起步

透過完成課程獲得認證

開始
廣告
© . All rights reserved.