I went through my entire C # reference book and could not find what '$' is.
I understood only that this is somewhat similar to the verbatim string '@'.
Console.WriteLine($"?"); How does this affect the string?
The prefix $ in front of the line means that the interpolated line comes next.
Interpolation is used to conveniently construct a string. At the same time, the expression of interpolated lines can look like a line template, in which language expressions can be used.
Interpolated strings are easier to understand with respect to arguments, compared to composite formatting.
Example:
var s = $"Name = {name}, hours = {hours:hh}"; Compared to string.Format
var s = string.Format("Name = {0}, hours = {1:hh}", name, hours); An important difference from the same string.Format :
String interpolation is transformed at. This is where you can find out how you’d like to see it.
The interpolated string at the time of compilation is transformed into an equivalent call to string.Format . This leaves the localization support as before (although still with the traditional formatting of strings) and does not allow you to add any code injection to the string after compilation.
This feature came with the release of C # 6 .
You can read more in MSDN Help.
String.Format a specification that says, or just an implementation detail? - Qwertiy ♦This is string interpolation, a handy thing that allows you to write an expression:
int i=1; Console.WriteLine($"i={i}"); Learn more here: https://msdn.microsoft.com/ru-ru/library/dn961160.aspx
Source: https://ru.stackoverflow.com/questions/603372/
All Articles