+ 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); } } }

23rd Mar 2018, 11:52 AM
Sylv1a
Sylv1a - avatar
3 Respuestas
+ 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/
23rd Mar 2018, 12:46 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 3
thanks
23rd Mar 2018, 12:51 PM
Sylv1a
Sylv1a - avatar
+ 2
A better formatted string syntax is: string interpolatedStringExample =
quot;Name: {yourName}";
25th Mar 2018, 3:10 AM
LunarCoffee
LunarCoffee - avatar