Readline | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

3rd Mar 2018, 7:35 PM
G. Görkem Köse
G. Görkem Köse - avatar
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.
3rd Mar 2018, 7:40 PM
Jesse Bayliss
Jesse Bayliss - avatar
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!
3rd Mar 2018, 7:49 PM
G. Görkem Köse
G. Görkem Köse - avatar
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.
3rd Mar 2018, 7:59 PM
Jesse Bayliss
Jesse Bayliss - avatar
3rd Mar 2018, 8:07 PM
Jesse Bayliss
Jesse Bayliss - avatar