+ 23
What's the meaning of {0} ?
14 Réponses
+ 39
its like a varuable statement that will change depend on what the list is one
example:
int age = 18;
Console.WriteLine("Your age is{0}", age);
the output is Your age is 18
see the "age" word beside {0}?
it means the {0} is the variable that outdepend on the indentifer so the age is inputed to {0}
example
int age = 18;
string name = Console.ReadLine();
Console.WriteLine("Age is {0} and your name is {1}", age, name);
now theres 2 {} and 2 identifer beside {1}, its "age" and "name", the "age" its inputed to {0} because its in the front, and the "name" is inputed to {1} because its in backward of the "age"
+ 13
The name given to {0} is called "placeholder". It tells the argument of ReadLine() in this case that there is a variable whose value is going to get inserted or placed at the position of {0} in the string. The "0" means its the first variable, so the second will be {1} and so on.
+ 4
{0} is a placeholder for your variable.
eg: a = 1 console.writeline("{0}",a);
if there is another variable the '0' increaments to '1' that is {1}.
eg: a=1 & b=2
console.writeline("a is {0} ] and b is {1}", a, b);
0
it's a placeholder...
0
it's a place holder mainly used for formatting.
0
in c# 6 you can use now string interpolation where if you have a name variable you can format something like below.
using static System.Console;
/* Static name space declaration to use the static method of the class directly with no class name*/
var name= "Asish";
var lastName="Mohapatra";
var data=quot;hi ! my name is {name} and my last name is {lastName};
Writeline(data);
Output
hi ! my name is Asish and my last name is Mohapatra.
Explanation
Here we have used $ to indicate that we are using string interpolation.
instead of using {0} or {1} now we are using exact variable.
This is available only on C# 6 !!!!!
0
{0} placeholder
for your variable
- 1
Thanks
- 1
its a hole between event horizon.
- 1
null maybe.
- 3
input function
- 4
so its not necessary to include????
- 4
Placeholder
0
- 4
input