Saturday, January 3, 2015

C# 6.0–String Interpolation

This blog post is part of C# 6.0 Features Series.
As we all know, C# 6.0 provides lots of small enhancements to the language and string interpolation is one of them. In this blog post we are going to learn how this small new feature can help us for string concatenation.

So let’s take small example, Where I have created a new example of string concatenation. Following is a code for that.
using System;
namespace StringInterpolation
    class Program
        static void Main(string[] args)
            string name = "Jalpesh Vadgama";

            //Old way of string concentaionation 
            Console.WriteLine("My name is" + name);
            Console.WriteLine("My name is {0}", name);

            //New way of doing this
            Console.WriteLine("My name is {name}");

Here if you see above code you will understand that I have written both way of doing string concatenation. Earlier we have used to do concatenation with + operator or we were using string.format place holder for variable like “{0}” and then put that variable in function itself. But in the new way of string concatenation you can put directly variable with “\{your variable name}”.

With this way code look more beautiful and readable. Isn’t it and when you run this application it will works fine like below.


That’s it. Hope you like it. Stay tune fore more!.

Note: You can get code of all example of C# 6.0 new features at following location on github.


Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog


My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews