Reprint Source:
78726825;
52612610;
The use of $ in C #: is to replace String.Format (); The original assignment requires placeholders and variables, when the need to stitch multiple variables will cause the statement too long and so difficult to understand the problem, $ "" is to replace the String.Format (),
The C # variable {} in the string can be included to achieve the purpose of identifying C # variables. $ "{ID}"; Expressions are also supported, using $ "{( your expression )}"
varK ="a"; vara0 ="User"; varA1 ="Id"; varA2 =5; varCCC =string. Format ("select * FROM {0} where {1} = {2}", A0, a1, A2); varCCB = $"Select * From {a0} where {A1}={A2}";
Of course also supports the String.Format () format, such as:
varK ="a"; varK4 = $"{k,5}"; varK3 =string. Format ("{0,5}", K); varK2 =DateTime.Now; varC = $"{k2:yyyy}"; C=string. Format ("{0:yyyy}", K2);
use a very simple $ after write two double quotes "", the variable is surrounded by {}.The comparison is interesting: The new formatting also supports direct assignment of any expressionbtn. Text = $ "{(btn. text== ""?: "null": BTN. Text)} "; Use () when assigning a value.
Interesting methods of C # Base-string class _2 ($)