I'm learning C# and came across this small piece of code:
{
class Program
{
static void Main(string[] args)
{
int age = 20;// declaring variable and assign 20 to it.
Console.WriteLine("You are {0} years old.",age);
Console.ReadLine();
}
}
}
I dont understand how {0}
will output 20. I mean it's not like an array index or anything so how does it know it's referring to the variable age
? I see the variable after the comma but would that mean that if I put {1} then it would retrieve the variable after age?
Also what is this feature called in C# I can't seem to locate it.