# Console.WriteLine()

It is similar to Console.Write method, except it adds a current line terminator to the output.

# Exercise 1

Run this program in your IDE. What do you see?

using System;

class MainClass
{
  public static void Main ()
  {
      Console.WriteLine(0);
      Console.WriteLine(-2);
      Console.WriteLine(10 / 5);
      Console.WriteLine("Hello");
      Console.WriteLine(1 != 2);
      Console.WriteLine(4 == 2 * 2);
      Console.WriteLine(14 == 7);
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

What is the different between output of this program and Console.Write Exercise 1.

# Exercise 2

What is the output of this program? Answer it without running it in your IDE.

using System;

class MainClass
{
  public static void Main ()
  {
      Console.WriteLine("");
  }
}
1
2
3
4
5
6
7
8
9

Now run the program in the IDE.

  1. What is the output?
  2. Does it match your expectation?

# Exercise 3

What is the output of this program? Answer it without running it in your IDE.

using System;

class MainClass
{
  public static void Main ()
  {
      Console.WriteLine("My name is ", "Talha");
  }
}
1
2
3
4
5
6
7
8
9

Now run the program in the IDE.

  1. What is the output?
  2. Does it match your expectation?

If the output does not match your expectation, then don't worry. We will discuss it in further detail Composite Formatting.

Last Updated: May 4, 2020, 6:37 PM