+ 4
Taking multiple values from the user
what will happen if i write the code int age=Convert.ToInt32(Console.ReadLine()); int sal=Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Your age is {0}",age); Console.WriteLine("Your salary is {1}",sal); What error will come and why? Please do help. Thank You
5 Réponses
+ 5
Your mistake is the placeholder in the second writeline it should be 0 instead of 1. See here
https://code.sololearn.com/cpi7Sd2SEKx4/?ref=app
+ 4
Sorry, I meant placeholder.
+ 4
Starting with C# 6 we already have another way. Formally called string interpolation.
You can write code like this.
Console.WriteLine(quot;Your age is {age}");
this new approach allows you to directly embed the variables themselves. and you clearly see which variables value you will have in output.
By the way every Console.WriteLine begins from 0, so that why in second Console.WriteLine you must write {0} , instead of {1}.
+ 2
playground or visual studio
+ 2
@DZZZ. Well done did not spot that one.
Please may I point out a
Console.WriteLine("Your age is {0}",age);
{0} is a placeholder
int *ip;
*ip is a pointer