C# Output
Printing text and values.
C# Output
To output values or print text in C#, you can use the WriteLine() method:
Console.WriteLine("Hello World!");
You can add as many WriteLine() methods as you want.
Write() Method
There is also a Write() method, which is similar to WriteLine().
The only difference is that it does not insert a new line at the end of the output:
Console.Write("Hello World! ");
Console.Write("I will print on the same line.");
Examples
WriteLine Example
Outputting multiple lines.
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.WriteLine("I am learning C#");
Console.WriteLine("It is awesome!");
}
}Write Example
Outputting on the same line.
using System;
class Program
{
static void Main(string[] args)
{
Console.Write("Hello ");
Console.Write("World!");
}
}Calculations
Outputting the result of a calculation.
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(3 + 3);
}
}