如何使用 C# 在控制檯上列印一行?
在 C# 中,要顯示一行,使用 Console.Write()。
Console 在控制檯上顯示結果。我首先設定一個字串。
string str = "Tom Hanks is an actor";
現在顯示上面的行。
Console.WriteLine(str);
以下是完整的程式碼 −
示例
using System; namespace Program { public class Demo { public static void Main(String[] args) { string str = "Tom Hanks is an actor"; Console.WriteLine("Displaying a line below"); Console.WriteLine(str); Console.ReadLine(); } } }
輸出
Displaying a line below Tom Hanks is an actor
廣告