Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

What’s New in C# 6.0? - String Interpolation

0.00/5 (No votes)
25 Nov 2014 1  
String interpolation in C# 6.0

Did you download the new Visual Studio 2015 IDE? If not, try the preview version before it actually releases and start improving your coding skills with the forthcoming IDE from Microsoft. Today, we are going to explore another new feature of C# 6.0 coming with this release.

Let’s continue the series “What’s new in C# 6.0?” and show you what’s coming with C# 6.0 in terms of string interpolation / string concatenation.

Don’t forget to read my previous post on this series: “What’s new in C# 6.0? - Setting default values to Auto Properties”.

String concatenation – we regularly use it to show different records to the user. To do this, we either use the ‘+’ symbol or the string.Format method to format and organize various strings. This now becomes old days mechanism.

Old ways of string concatenation (www.kunal-chowdhury.com)

In C# 6.0, Microsoft added new feature to accelerate your coding skill. Now you can put expressions directly in the string literal to show the values in a proper formatted manner. You can also easily align or specify different format to your values. Not only this! You can now write conditions within string literals with additional strings as content.

Here are a few examples of what we can do now with C# 6.0 in Visual Studio 2015 and .NET 4.6:

Hope you liked this feature. Microsoft is still working on this to improve a lot in string interpolation/string concatenation to add more a easier way to provide conditions in strings. Wish to see them soon in the coming release of Visual Studio 2015.

It’s not the end. More to come in this series. Stay tuned to my blog for updates. Till that time, enjoy reading my other posts. Why don’t you subscribe to my blog’s RSS Feed and Email Newsletter? This will give you immediate update in your inbox. Connect with me over Twitter, Facebook and Google+ to get the updates which I share.

Reference: http://www.kunal-chowdhury.com
You may like to follow me on twitter @kunal2383 or may like the Facebook page of my blog http://www.facebook.com/blog.kunal.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here