:::: MENU ::::

Friday, April 24, 2015

One of the best features in VS2015 is Roslyn as main compiler for .Net. This opens a new world of possibilities for writing code in a more elegant way. One of these options is the ability to use String Interpolation instead of the classic String.Format () .

If anyone would not read the Wikipedia link or study a little, maybe it is best see the following lines of code
using System;
 
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string name = "Valentino";
int age = 7;
 
var data1 = string.Format("name:{0}, age:{1}", name, age);
Console.WriteLine("classic string format - {0}", data1);
 
var data2 = $"name:{name}, age:{age}";
Console.WriteLine("string interpolation - {0}", data2);
Console.ReadLine();
}
}
}
Note: if did not know it the ability to use String Interpolation was in the Top 10 of the most requested features to the new version of Visual Studio (link)
As the saying goes for taste colors. To my personally I like this format to work with Strings. And I believe that the recommendation of use is very clear…
Do not use String Interpolation if you are sharing code with a team where there are people who use Visual Studio 2013.
References: