The @ symbol in C # is actually a lot of usage, so let's look at what's amazing about @.
1. Qualifying string
Precede the string with the @ symbol to indicate that the escape character "No" is being processed.
If we write a path to a file, such as a text.txt file under the "d:\ text file" path, the words are written as follows without the @ symbol:
String fileName = "d:\\ text file \\text.txt"; If you use the @ symbol, it's easier:
String fileName = @ "d:\ text file \text.txt"; 2. Let string Cross Line
Sometimes a string written in a line can be very long (such as SQL statements), not using the @ symbol, a writing is this:
string strSQL = "SELECT * FROM HumanResources.Employee AS e"
+ " INNER JOIN Person.Contact AS c"
+ " ON e.ContactID = c.ContactID"
+ " ORDER BY c.LastName";
With the @ symbol, you can change the line directly:
string strSQL = @"SELECT * FROM HumanResources.Employee AS e
INNER JOIN Person.Contact AS c
ON e.ContactID = c.ContactID
ORDER BY c.LastName";
3. Usage in identifiers
C # does not allow keywords to be used as identifiers (class names, variable names, method names, table space names, and so on), but if you add @ then 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");}}}