Prior to C# 6.0 String concatenation sometimes became challenging in older versions of c#, primarily since we need to write numeric placeholders and than variables in same order. Consider below example
string firstName = "Shakti";
string lastName = "Tanwar";
string title = "Mr.";
string fullName = string.Format("{0} {1} {2}", title, firstName, lastName);
In above example, placeholders i.e. {0} ,{1} and {2} and kinda magic numbers. Also the order in which we are passing the parameters becomes very important so chance of mistakes are more. We should avoid magic numbers in code since they hamper readability and code understanding.
A handy addition in C# 6.0 is named placeholders which also removes the reliance on parameter ordering while creating strings e.g. Above code can be rewritten in C# 6.0 as :
string firstName = "Shakti";
string lastName = "Tanwar";
string title = "Mr.";
string fullName = string.Format("\{title} \{firstName} \{lastName}");
Console.WriteLine("\{title} \{firstName} \{lastName}");
As you can see syntax is self-explanatory. Don’t forget to add leading “\” with named placeholders else it will be treated as a string and output as is.