C# Console.WriteLine() Tutorial

In C#, the Console.WriteLine() method is used to display text in the console window. Its basic syntax is as follows:

Console.WriteLine(string);

Among them, the string parameter is the text content to be output. For example:

Console.WriteLine("Hello, World!");

The above code will output “Hello, World!” in the console window. The Console.WriteLine() method also supports the use of placeholders to format the output, for example:

Console.WriteLine("My name is {0} and I am {1} years old.", "Alice", 30);

The above code will print out “My name is Alice and I am 30 years old.” In this example, “{0}” and “{1}” are placeholders corresponding to the values in the subsequent argument list.

It is important to note that the Console.WriteLine() method automatically adds a newline character after each output, so each time the method is called, the content will be displayed on a new line.

bannerAds