Many of the details of programming are very important to us, or a small letter error will cause the program can not run, I have experienced such a thing, for programming should pay attention to the problem, we should often collect and organize their own a handbook, today we talk about the use of the @ symbol in C # and notice matters.
Many of the details of programming are very important to us, or a small letter error will cause the program can not run, I have experienced such a thing, for programming should pay attention to the problem, we should often collect and organize their own a handbook, today we talk about the use of the @ symbol in C # and notice matters.
The usage in a string
The character @ indicates that the string that follows is a "verbatim string" (verbatim string).
@ can only function on string constants.
1. For file path
The following are the referenced contents:
String S_filepath = "C:\\Program Files\\microsoft.net\\test.txt";
Equivalent
The following are the referenced contents:
String S_filepath =@ "C:\Program files\microsoft.net\test.txt";
2. A string that is represented by @ can span several lines. It is more convenient to write JS or SQL code in CS.
The following are the referenced contents:
String s_multirows = @ "Line1
Line2
Line3 ";
String s_javascript = @ "
";
The use of the two identifiers
In the C # specification, @ can act as the first character of an identifier (class name, variable name, method name, and so on) to allow a reserved keyword in C # as its own defined identifier.
Such as
The following are the referenced contents:
Class @class
{
public static void @static (bool @bool) {
if (@bool)
System.Console.WriteLine ("true");
Else
System.Console.WriteLine ("false");
}
}
Class Class1
{
static void M () {
Clu0061ss.stu0061tic (TRUE);
}
}
Note that @ is not part of the identifier itself, although it appears in the identifier.
Therefore, the above example defines a class named class and contains a method named Static, and a parameter name for the formal parameter of bool.
This provides a convenient way to migrate across languages. Because, a word in C # as a reserved keyword, but in other languages may not be.