Three Functions of @ on c,

Source: Internet
Author: User

Three Functions of @ on c,
Previously, I only knew that @ in C # added the @ identifier in front of the \ Escape Character for writing the file path. I didn't expect @ to have other functions.

1. Ignore escape characters

For example

String fileName = "D :\\ text file \ text.txt ";

After @ is used

String fileName = @ "D: \ text file \ text.txt ";

2. Cross-line string

For example

String strSQL = "SELECT * FROM HumanResources. employee AS e "+" inner join Person. contact AS c "+" ON e. contactID = c. contactID "+" order by c. lastName ";

After @ is used

String strSQL = @ "SELECT * FROM HumanResources. Employee AS eINNER JOIN Person. Contact AS cON e. ContactID = c. ContactIDORDER BY c. LastName ";

3. Usage in identifiers

C # is not allowed to use keywords as Identifiers (Class Name, variable name, method name, tablespace name, etc.), but if you add @, you can

For example

Public static void @ static (int @ int) {if (@ int> 0) {System. console. writeLine ("Positive Integer");} else if (@ int = 0) {System. console. writeLine ("Zero");} else {System. console. writeLine ("Negative Integer ");}}

 

Related Article

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.