C# Output With Example

 C# Output


To the output values or print text in C#, you can use to the WriteLine() method:

C# Output With Example
C# Output With Example

Example:

using System;

namespace MyApplication

{

  class Program

  {

    static void Main(string[] args)

    {

      Console.WriteLine("Hello World!");

    }

  }

}

Here You can add as many WriteLine() methods as you want. Note that it will be add a new line for each method:

Example:

using System;

 

namespace MyApplication

{

  class Program

  {

    static void Main(string[] args)

    {

      Console.WriteLine("Hello World!");

      Console.WriteLine("I am Learning C#");

      Console.WriteLine("It is awesome!");

    }

  }

}

Here You can also output numbers, and the perform mathematical calculations:


Example:

using System;

namespace MyApplication

{

  class Program

  {

    static void Main(string[] args)

    {

      Console.WriteLine(3 + 3);

    }

  }

}

The Write Method

There is also the Write() method, which is similar to the WriteLine().

The only difference is to that it does not insert a new line at the end of the output:

Example:

using System;

 namespace MyApplication

{

  class Program

  {

    static void Main(string[] args)

    {

      Console.Write("Hello World! ");

      Console.Write("I will print on the same line.");

    }

  }

}

Note that we will add an extra space when needed (after "Hello World!" in the example above), for the better readability.

In this post, we will only use the WriteLine() as it makes it easier to read the output of code.


Post a Comment

Post a Comment (0)

Previous Post Next Post