Home

C# Curly Braces/Brackets And Strings - 3 Ways

Also known as interpolation?

public class Solution
{
    static void Main()
    {
        string myName = "Ren";
        int myAge = 51;
        string myHobby = "Motorcycling";
        string myResponse = "";

        Console.WriteLine("Hi {0}, you are {1} years old and your hobby is {2}", myName, myAge, myHobby);

        myResponse = string.Format("Hi {0}, you are {1} years old and your hobby is {2}", myName, myAge, myHobby);
        Console.WriteLine(myResponse);

        myResponse = $"Hi {myName}, you are {myAge} years old and your hobby is {myHobby}";
        Console.WriteLine(myResponse);
    }
}

Reader's Comments

Post Your Comment Posts/Links Rules

Name

Comment

Add a RELEVANT link (not required)

Upload an image (not required)

No uploaded image
Real person number
Please enter the above number below




Home
Admin Ren's Biking Blog