String interpolation - C# 6 Language New features

string-interpolation-example-Csharp-6-new-featuresAfter releasing C# 6 Microsoft deprecate the syntax of some old features. Today I am going to share one new feature named "String Interpolation".  
String Interpolation is the kind of string concatenation (not exactly).It is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.
String interpolation exists from the first release of C#. We are performing string interpolation using+ operator or string.Format function to produce a resultant string. This new feature is definitely going to save your time and make your code more readable. Before few weeks Microsoft refurnished the syntax of  string interpolation (hope they will not change it again). Instead of  using \{} at placeholder simple put "$" as prefix in the string.
Now, we are going to discuss string interpolation with two examples. Notice yourself how new feature is going to help you.

Old syntax to concatenate string

class Program
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }

        static void Main(string[] args)
        {
            Program p = new Program
            {
                FirstName = "Bhavik",
                LastName = "Patel"
            };

            Console.WriteLine("First Way => First Name: " + p.FirstName + " Last Name: " + p.LastName + "\n");

            // OR 
            Console.WriteLine(string.Format("Second Way => First Name:{0} and Last Name: {1}",p.FirstName, p.LastName));
            Console.Read();
        }
    }
The first way is most common, we concatenate the strings using + operator. Sometime this method takes more time to set output string. In second way we use better and smarter approach. We use String.Format which is more readable than the first way. You can learn more about String.Format and how to generate different kind of output from here.
Output

In C# 6

class Program
{
    public string FirstName { get; set; }
    public string LastName { get; set; }

    static void Main(string[] args)
    {
        Program p = new Program
        {
            FirstName = "Bhavik",
            LastName = "Patel"
        };

        Console.WriteLine($"string interpolation => First Name: {p.FirstName} and Last Name: {p.LastName}");

        Console.Read();
    }
}
C# 6 use $ to construct interpolated strings. Instead of, placeholders ({0} and {1}) you can directly use parameters ({p.FirstName} and {p.LastName}) as placeholders.
Output

Formatting
Please visit my next article for different type of formatting examples in C# 6 string interpolation.