Console.WriteLine()是C#中用于打印輸出的方法。它可以接受一個(gè)或多個(gè)參數(shù),并將它們輸出到控制臺(tái)窗口。
下面是一些使用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()方法會(huì)將參數(shù)中的內(nèi)容輸出到控制臺(tái)窗口,并自動(dòng)換行。