String Interpolation in C#
String interpolation has been around since C# version 6, so it is not exactly new, but even so, I sometimes encounter developers who are not familiar with the format. In this article, we will explore some of the features of string interpolation; the good, the bad and the ugly. Before the introduction of string interpolation, you only had two choices when it came to compiling a string with variable data. You either had to concatenate the string and the variables together, or you had to use composite formatting, as shown below. class Program { static void Main(string[] args) { string name = "Clark Kent"; DateTime now = DateTime.Now; // Concatenate var concatMsg = "Hi there, " + name + ". Today is " + now.DayOfWeek + " and the time is " + now.ToString("HH:mm") + "."; Console.WriteLine(concatMsg); // Composite var co...