C # @ symbol usage

Source: Internet
Author: User

1. Restrict strings
Add the @ symbol before the string to indicate that the Escape Character "no" is processed.
If we write a file path, such as the text.txt file under "D:/Text File", without the @ symbol, the statement is as follows:
 
StringfileName = "D: // text file // text.txt ";
 
If you use the @ symbol, it will be relatively simple:
StringfileName = @ "D:/Text File/text.txt ";
2. Cross-line string
Sometimes a string is long in a line (such as an SQL statement) and does not use the @ symbol:
 
 
String strSQL = "SELECT * FROM HumanResources. Employee AS e"
+ "INNER JOINPerson. Contact AS c"
+ "ON e. ContactID = c. ContactID"
+ "ORDERBY c. LastName ";
 
After adding the @ symbol, you can directly wrap the line: www.2cto.com
 
 
String strSQL = @ "SELECT * FROM HumanResources. Employee AS e inner join Person. Contact AS c ON e. ContactID = c. ContactID ORDERBYc. 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:
 
 
Namespace @ namespace
{
Class @ class
{
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 ");
}
}
}
}
 
From Ling Yu's column

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.