+ 1
Where is the explanation on the $ in the c# course
I forgot what it meant and i cant find it on the courses
3 ответов
+ 2
I think what you’re thinking of is string interpolation. its basically just formatting strings without using concatenation.
heres a link for more information:
https://www.w3schools.com/cs/cs_strings_interpol.php
+ 2
sign $ is used to denote interpolated strings. Interpolated strings are a way to embed expressions or variables within a string, making string formatting more convenient.
int x = 5;
string message = quot;The value of x is {x}.";
Console.WriteLine(message);
0
In C#, the dollar symbol ($) is a feature that allows you to get the variable in a string, without moving it out of the string, and you don't have to use something like "{0}{1}", var1, var2.
For example:
int brother = 18;
int sister = 16;
Console.WriteLine(quot;My sister is {sister} years old and my brother is {brother} years old. My sister is {brother-sister} age younger than my brother."
The same works with string or any other types.
You can perform any calculations with it as well.
Why is it useful?
It works faster than string concatenate, and it saves your time, as well!