+ 4
$ sign in c#
Console.WriteLine(
quot;\n\tYour result is {result}."); why do we use $ sign there in c# what is the usage5 Réponses
+ 4
It's the new feature in C# 6 it is called Interpolated Strings.
The dollar tells the compiler. This string contains placeholders so instead of writing
Console.WriteLine("\n\tYour result is {0}.", result);
You can write now the variable is inline and the code it better readable.
Console.WriteLine(quot;\n\tYour result is {result}.");
https://stackoverflow.com/questions/32878549/whats-with-the-dollar-sign-string
+ 3
now ı know we don not use special place holders but use it directly like
string str ="name";
Console.WriteLine(quot;hello! ,{str}");
in curly braces inside the string
+ 2
https://code.sololearn.com/c9Sy3XspIEZB
I extended my place holder experiment.
Console.WriteLine(String.Format("counting from 1 to 5 {0}{1}{2}{3}{4}", a,b,c,d,e));
Console.WriteLine(String.Format(quot;counting from 1 to 5 {a}{b}{c}{d}{e}"));
are the same.
0
That is it. It won't work without the $-sign. That sign is thete for a reason.
Good question.
- 1
it might bu related to arrays ot data types ??
hmm??
I saw but my mind is not clear
interpolated strings or smth but ...