All Type Coding

Search Here

How to Reading and writing to a console

First of all Open visual studio go to-> file ->new ->project
after that select Console Application like my previous tutorials. after that
copy below code and paste in your project
Here we will discuss about 
1. Reading from the console
2. Writing to the console
3. There are two ways to write to console
     a) Concatenation syntax 
     b) Place holder syntax 

Code samples for Concatenation 
using System;
class Program
{
    static void Main()
    {
        Console.WriteLine("Please enter your name");
        string UserName = Console.ReadLine();
        // Concatenate name with hello word and print
        Console.WriteLine("Hello " + UserName);
    }
}

Code samples for Place holder
using System;
class Program
{
    static void Main()
    {
        Console.WriteLine("Please enter your name");
        string UserName = Console.ReadLine();
        //Placeholder syntax to print name with hello word 
        Console.WriteLine("Hello {0}", UserName);
        Console.ReadKey();   
 }
}
Output will be same:








Diffrence vs WriteLine and Write method in c#
The Write () method outputs one or more values to the screen without a new line character.

The WriteLine() always appends a new line character to the end of the string. this means any subsequent output will start on a new line.

No comments :

Post a Comment