+ 1
What does {0} mean in C#
4 Respuestas
+ 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