Console.WriteLine()是C#中用于打印输出的方法。它可以接受一个或多个参数,并将它们输出到控制台窗口。
下面是一些使用Console.WriteLine()方法的例子:
string name = "John";
Console.WriteLine("My name is " + name);
int age = 25;
Console.WriteLine("I am " + age + " years old");
string firstName = "John";
string lastName = "Doe";
Console.WriteLine("My name is {0} {1}", firstName, lastName);
或者使用字符串插值(String Interpolation):
string firstName = "John";
string lastName = "Doe";
Console.WriteLine($"My name is {firstName} {lastName}");
int number = 42;
Console.WriteLine("The answer to the ultimate question of life, the universe, and everything is {0:D}", number);
上述例子中的Console.WriteLine()方法会将参数中的内容输出到控制台窗口,并自动换行。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: c#中await的使用方法是什么