In C#, there are several ways to output values or print text in console. Here, we will explain Console.WriteLine() and Console.Write() Method. The use of these two method also is the difference between them. There are many other methods for outputting data in C#, such as Console.Error.WriteLine() for writing to the error stream, and System.Diagnostics.Debug.WriteLine() for writing to the debug output window.
The most common method is to use the Console.WriteLine() method, which writes a string of text to the console and adds a newline character at the end.
Example
Console.WriteLine("Rohatash");
Console.WriteLine("Rahul");
Console.WriteLine("Ritesh");
Console.WriteLine("Manoj");
Output
You can also use string interpolation to output values along with text. String interpolation allows you to embed expressions inside a string literal by using the $ symbol before the string and enclosing the expressions in curly braces {}.
Example
string name = "Rohatash";
int age = 35;
Console.WriteLine($"My name is {name} and I am {age} years old.");
This will output the text "My name is Rohatash and I am 35 years old." to the console.
Output
If you want to output a string without appending a newline character, you can use the Console.Write() method instead.
Console.Write("Rohatash");
Console.Write("Rahul");
Console.Write("Ritesh");
Console.Write("Manoj");
Output
This will output the names without a newline character.