$ sign in c# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

$ sign in c#

Console.WriteLine(

quot;\n\tYour result is {result}."); why do we use $ sign there in c# what is the usage

9th Jun 2017, 3:01 PM
code
code - avatar
5 Answers
+ 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
9th Jun 2017, 5:39 PM
sneeze
sneeze - avatar
+ 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
9th Jun 2017, 6:29 PM
code
code - avatar
+ 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.
9th Jun 2017, 10:02 PM
sneeze
sneeze - avatar
0
That is it. It won't work without the $-sign. That sign is thete for a reason. Good question.
9th Jun 2017, 8:05 PM
sneeze
sneeze - avatar
- 1
it might bu related to arrays ot data types ?? hmm?? I saw but my mind is not clear interpolated strings or smth but ...
9th Jun 2017, 3:05 PM
code
code - avatar