Sunday, April 5, 2015

How to communicate with Console

Here we will learn on how to communicate with Console

a. How to read message
b. How to write message

a. How to read message from our console.

Important Note: Please keep in mind that C# is a case sensitive.
Meaning that name and NAME are different.

Let's have sample program that illustrate the read/write to console


using System;      // This is common for all our c# programs
class Program
{
    static void Main()
    {
        // To show a message on the console to enter name
        Console.WriteLine("Enter your name");
        // Reading the name from console
        string Name= Console.ReadLine();
        // Concatenate name with hello word and print
        Console.WriteLine("Hello " + Name);

       }
}

There is another method to print the message on console.

  //Below syntax is called Placeholder syntax to print name with hello word 
   //Console.WriteLine("Hello {0}", Name);

No comments:

Post a Comment