0
What is the use of {1} like placeholdersin the program
3 Réponses
+ 1
You use them as a way of saying where something would be in your text.
for example:
Console.WriteLine("Hi, my name is {0} and your name is {1}!", myName, yourName)
0
for example:
Console.WriteLine("this is your count {0}", yourVariable);
the {0} is the value from your variable.
0
Before I go into it, think of it as the average function. The first argument is a string which is printed. The second argument is a table (it's not a table but just say it is for a moment) filled with variables.
When you're writing the first argument, you can reference a variable (via it's position in the table, starting from 0) from inside the table. You do so by typing something like {0}, {1} and so on. Here's an example.
static void main {
Console.WriteLine("Hey {0}. How are you, {1} ?", name, title)
}
Now, say that the title variable wasn't there but the {1} was. You'd get an error because it doesn't exist.