+ 2
Why is after "Hello {0}", yourName. The word yourName again? (See code in description)
namespace SoloLearn { class Program { static void Main(string[] args) { string yourName; Console.WriteLine("What is your name?"); yourName = Console.ReadLine(); Console.WriteLine("Hello {0}", yourName); } } }
3 Answers
+ 7
In this code {0} is a placeholder for yourName variable. That means if the value of yourName is "Isabel", then your code will print "Hello Isabel". While printing multiple variables in single statement, you'll have to use multiple placeholders like {0}, {1}, {2} and so on.
For details: https://www.sololearn.com/learn/CSharp/2584/
+ 3
thanks
+ 2
A better formatted string syntax is:
string interpolatedStringExample =
quot;Name: {yourName}";