+ 1

What does {0} mean in C#

14th Jul 2019, 9:22 PM
Anas Omari
Anas Omari - avatar
4 odpowiedzi
+ 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.”);
14th Jul 2019, 9:46 PM
nk361
nk361 - avatar
+ 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
14th Jul 2019, 9:33 PM
nk361
nk361 - avatar
+ 1
Plz five me example
14th Jul 2019, 9:38 PM
Anas Omari
Anas Omari - avatar
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
14th Jul 2022, 6:56 PM
bwv822 🇨🇦
bwv822 🇨🇦 - avatar