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