0
input c#
static void Main(string[] args) { String name; int age; double grade; Console.WriteLine("what is your name"); name = Console.ReadLine(); Console.WriteLine("may name is {0}",name); Console.WriteLine("how old are you"); age = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Im {1}", age); Console.WriteLine("my grade"); grade = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("my grade {2}", grade); } ((( why double variable not appear ?? and other two variable are appeare((
5 Answers
0
hi sanaa Hareb
whats the output of that code....
0
the output :
what is your name
Ali
my name is Ali
how old are you
28
but for double variable writen unhandle exception
0
hi Sanaa Hareb
here a fixed version of your code. the exception in your code was caused by age and grade lines...
https://code.sololearn.com/cFv3QsSjyUJ9/?ref=app
Console.WriteLine(âmy grade {2}â, grade);
this is because if you want to print grade to the screen it needs to be zero and putting it as 2 prints null to the screen and causes an error
0
Do you know for what use is {number}?
{0} means that it will take first variable that appears after comma in console.writeline
{1} means that it will take second variable that appears after comma in console.writeline
{2} means that it will take third variable that appears after comma in console.writeline
...
Console.Writeline("I'm printing {0}{1}{2}", first,second,third);
If you have obe parameter in cw, you don't need that, only if you want to print in another order then use it.
đđđ
- 1
those {n} indicates the function to replace it with the n+2 parameters. assuming the first parameter (the string) is 1.
since syntax is {2} (the 4th parameter) and {1} (the 3rd parameter) but theres only 2 parameters. the function will try to find the value that doesnt exist.