0
Readline
static void Main(string[] args) { string yourName; Console.WriteLine("What is your name?"); yourName = Console.ReadLine(); Console.WriteLine("Hello {0}", yourName); In the last code above, why did we write yourName after writing "Hello {0}"? In the previous section, the system said the {0} is a placeholder for the value. So I thought that {0} holds place for yourName then we don't need to write yourName again after writing "Hello {0}". What is the tricky point here, is there anyone who can help me?
4 Answers
0
The {0} means the parameter at index 0 that you pass to WriteLine. Console.WriteLine(quot;Hello {yourName}") would format it using the variable yourName.
0
The {0} means the parameter at index 0 that you pass to WriteLine.
What did you exactly mean by index 0, parameter and pass?
Iâm sorry but Iâm new in these coding things so trying to understand completely and in a detailed way.
Then, you said it would format it, so it wonât work right?
OMG ITâS TOO COMPLICATED!
0
To pass a parameter is to use it in when calling a function. A parameter is a value passed to a function. C# uses a 0 based index. The first value used to format the string is at index 0. The second value is at index 1. Etc...
Formatting means taking the values and putting them in the string, and in the case of C# this means creating a new string object so the original string is left alone.