SoFunction
Updated on 2025-03-08

Detailed explanation of several ways to use @ symbols in C#

1. Qualified strings
The escape character "not" is processed by adding the @ symbol before the string.
If we write a file path, for example, a file under the "D:/text file" path, if the @ symbol is not added, the writing method is as follows:
stringfileName="D://text file//";
It will be easier if you use the @ symbol:
stringfileName=@"D:/text file/";

2. Let the string cross line
Sometimes a string is written in a line very long (such as a SQL statement) without using the @ symbol. One way to write it is like this:
Copy the codeThe code is as follows:

string strSQL="SELECT * FROM AS e"  
+"INNER AS c"   3.+"ON ="   4.+"ORDERBY ";  

Add the @ symbol and you can wrap the line directly:
Copy the codeThe code is as follows:

string strSQL=@"SELECT * FROM AS e INNER JOIN AS c ON = ";  

3. Usage in identifiers
C# does not allow keywords to be used as identifiers (class names, variable names, method names, tablespace names, etc.), but if @ is added, it will be fine, for example:
Copy the codeThe code is as follows:

namespace @namespace  
{  
  class @class   4.     {  
        public static void @static(int @int)   6.         {  
            if (@int > 0)   8.             {  
                 ("Positive Integer");   10.             }  
            else if (@int == 0)   12.             {  
                 ("Zero");   14.             }  
            else   16.             {  
                 ("Negative Integer");   18.             }  
         }  
     }  
}