Utilizor
Contact Us

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);
  }
}

Concatenation

Combining text and variables in output.

using System;

class Program
{
    static void Main()
    {
        string name = "John";
        Console.WriteLine("Hello " + name);
    }
}

Formatting Output

Using placeholders for output.

using System;

class Program
{
    static void Main()
    {
        int age = 25;
        Console.WriteLine("Age: {0}", age);
    }
}