+ 1
What does {0} mean in C#
4 Answers
+ 2
Console.WriteLine(âHello, {0}! You are {1} year(s) old.â, âJeffâ, 20);
Hope this helps but the new way is through string interpolation, like this:
string name = âJeffâ;
int age = 20;
Console.WriteLine($âHello, {name}! You are {age} year(s) old.â);
+ 2
In a formatted print, {0}, {1}, {2} will match up with the paramters given after the string which will then be placed in those spots in the same order that they are listed
+ 1
Plz five me example
0
lets say you have:
string name = "devmonke"
string botname = "sololearn"
Console.WriteLine("Hello {0}, I'm {1}", name, botname)
this will print Hello devmonke, I'm sololearn
the name and botname variables at the end of the string in Console.WriteLine are what will be replaced by the {0} and {1}
you can add as many as you want {0}, {1}, {2} etc. just make sure you have enough variables to replace the {0} and however many you want