Custom Search

Monday, 21 September 2015

C#: Different Ways to Write Text on Console: Concatenation, Placeholder Syntax



In C sharp we have two ways in which we can write text on the console. The first method is using string Concatenation which is explained below.

Concatenation
In this we are plus symbol to concatenate two strings together.

Console.WriteLine("Please enter your name");

string Username: Console.ReadLine();

Console.WriteLine("Hello " + Username);


Placeholder Syntax
This method is most widely used as its more flexible, you can set the value in the placeholders which will display your text according, for example I want to Write a code where in I want whenever the user login to their account the system should display

Welcome First name Last name

Console.WriteLine("Enter your first name");

string FirstName: Console.ReadLine();

Console.WriteLine("Enter your LastName");

string LastName: Console.ReadLine();

Console.WriteLine("Hello {0},{1}", FirstName, LastName);

In this we can swap the value of 0 and 1 and the text will be displayed accordingly

Laptops