C# Output

In this lesson, you will learn about the different output operations in C#, their usage, and examples to better understand the topic.


C# Output Explained

To print or output a value in C#, use the Console.WriteLine() method:

Console.WriteLine ("Hello World! ");
Console.WriteLine ("I'm learning C#");

Output

Hello World!
I'm learning C#

This method will print the content of the string between the “”, then move to a new line. It also can print numbers.

Example

Console.WriteLine(21);

Output

21

C# Write Function

The Console.Write() function is similar to the WriteLine function. The difference is that the Write function does not add a new line after printing the value.

Example

Console.Write("Hello World! ");
Console.Write("I'm learning C#");

Output

Hello World! I'm learning C#

Concatenate and Print in C#

You can also use the output function in C# to concatenate two values and print them using the + operator.

Example

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

Output

Hello World!

This concludes the C# Output lesson. In the next lesson, you will learn about Variables in C#.