What is the {0} for in the code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the {0} for in the code?

23rd Oct 2016, 11:13 PM
Ryan Lyford
Ryan Lyford - avatar
4 Answers
+ 7
it's a place-holder, you can insert one or more values(any kind of value) inside a string. Remember that the indexer start from 0 'zero'! Example: String name= "LoL" int age = 21 Console.WriteLine("My name is {0} and i'm {1}", name, age)
24th Oct 2016, 6:22 AM
Marco Romanin
Marco Romanin - avatar
+ 3
More useful example: String name= "LoL"; int age = 21; string str = string.format("My name is {0} and i'm {1}", name, age); Then you can do with str whatever you wish...
24th Oct 2016, 9:18 PM
Ivan G
Ivan G - avatar
+ 1
it 's a place holder it will hold the place for variable to display and it follow the sequence of variable specify in the out put string . Like String firstname="Milind"; String lastname ="Gandhi"; Console.WriteLine("My name is {0}{1}",firstname,lastname);
29th Oct 2016, 5:15 AM
Gandhi Milind
- 6
that for set a value out of string value
23rd Oct 2016, 11:36 PM
Ömür Buruk
Ömür Buruk - avatar