Interesting methods of C # Base-string class _2 ($)

Source: Internet
Author: User

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 ($)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.