CSharp Basic Program

We need to use the Console.ReadLine() to Read something or Get Input in C# Console
Application and need to use Console.WriteLine() or Console.Write() in order to Write something or print Output in C# Console Application

The difference between WriteLine() and Write() :

- WriteLine() prints the string and the cursor moves to the next line after printing the string.

-  Write() prints the string and the cursor stays at the end of the printed string.

Simple C# Program:

using System;   //Namespace Declaration
class MyFirstClass     //Class Declaration
{
    Public static void Main() // Main method
    {
        Console.WriteLine("Hello World"); //Prints message
    }
}

 

using System;
namespace SampleProgram
{
  class MyFirstSample // Class Declaration
  {
    public static void Main(string[] args) //Main Method
    {
      Console.WriteLine("Please enter your name"); //Prints
      string name = Console.ReadLine(); //Read the input
      Console.WriteLine("Hello " + name); //prints with name
      Console.WriteLine("Hello World"); //prints
      Console.Write("Console Write Prints on "); //prints
      Console.Write("the Same line"); //prints on same line.
    }
  }
}

 

OUTPUT:

Output

 

Related Tutorials