Sunday, 21 February 2016

Reading and writing to a console



Reading from console:

 Console.ReadLine();;

Writing to console:
   
 Console.WriteLine();

There are two ways to write console
  • Concatenation
  • Place holder syntax – Most preferred

Example

Program

using System;
class Program
{
static void Main()
{
// Prompt the user for his name
Console.WriteLine("Please enter your name");
// Read the name from console
string UserName = Console.ReadLine();
// Concatenate name with hello word and print
Console.WriteLine("Hello " + UserName);
//Placeholder syntax to print name with hello word 
//Console.WriteLine("Hello {0}", UserName);
}
}



Output::



0 comments:

Post a Comment