When you try
Console.WriteLine("The answer is " , answer); //without placeholder
This wont give you error but would not print the answer
and the console output would be The answer is
since you havent told where to put the variable answer
in here. So if you want to print the answer you can use either concatenate using +
as suggested by other post or you have to use placeholder
Letz take an example to understand where to use what. Let say you have many variables to show in the output. You can use placeholder so that it would be easy to read. Such as
string fname = "Mohit";
string lname = "Shrivastava";
string myAddr = "Some Place";
string Designation = "Some Desig";
Now letz say we wanted to show some string on the output which is like
Hey!! Mohit
whose last name would be Shrivastava
is currently living at Some Place
and he is working as Some Desig
with so n so company.
Thus one of the way could be which is suggested by many of us.
Console.WriteLine("Hey!! " + fname + " whose last name would be " + lname + " is currently living at " + myAddr + " and he is working as " + Designation + " with so n so company.");
In this scenario Placeholder plays a vital role for better readability like
Console.WriteLine("Hey!! {0} whose last name would be {1} is currently living at {2} and he is working as {3} with so n so company.",fname,lname,myAddr,Designation);
With C#6.0 String Interpolation you can also do it in efficient way like
Console.WriteLine($"Hey!! {fname} whose last name would be {lname} is currently living at {myAddr} and he is working as {Designation} with so n so company.");