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
Name
Comment
Add a RELEVANT link (not required)
Upload an image (not required)
Uploading...
Home