Hello!
I was trying to use Visual Studio 2015 as my main development IDE for a while. The new versions are more stable, so I use it more and more and I’ve not opened Visual Studio 2013 for a while.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
You can also find with wonders like this
Saludos @ Madrid
/El Bruno
References:
Roslyn, https://github.com/dotnet/roslyn
String Interpolation, http://en.wikipedia.org/wiki/String_interpolation
String Interpolation User Voice, http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2312991-string-interpolations-in-c

Leave a comment