如何使用 C# 在控制台上打印一行?
csharpprogrammingserver side programming更新于 2025/7/12 8:37:17
在 C# 中,要显示一行,可以使用 Console.Write()。
控制台会在控制台上显示结果。我首先设置了一个字符串。
string str = "Tom Hanks is an act";
现在显示上面一行。
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

