Luke Warren Dev
Software Development Tips and Stories When I feel Like It

C# 6: Get rid of String.Format with Interpolated Strings

So I don't know about anyone else but I am loving Visual Studio 2015 and C# 6.

,
C# 6: Get rid of String.Format with Interpolated Strings

So I don't know about anyone else but I am loving Visual Studio 2015 and C# 6.

My current favourite feature is the string interpolation. Yes, yes, I know that PHP (and others) have had this for ages but here it is...

Often we would have to do stuff like this:

string first = "Luke"; 

string last = "Warren"; 

string fullName = String.Format("{0} {1}", first, last); 

What a pain!

Now, with string interpolation, we can shorten that last statement to:

string fullName = $"{first} {last}";

Simple but very handy! Just remember the dollar sign before the string. VS will show some nice syntax highlighting to help you out too.

More info: https://msdn.microsoft.com/en-us/library/dn961160.aspx


comments powered by Disqus