We should pay close attention to many details in programming. If a small letter error can cause the program to fail to run, I have experienced such a thing myself, for issues that should be paid attention to in programming, we need to collect and sort out our own manual frequently. Today we will talk aboutC #
The usage and precautions of the @ symbol in.
Usage in a string
Character @ indicates that the subsequent string is a "verbatim string" (verbatim string ).
@ Can only act on string constants.
1. Used for file path
The following is a reference clip:
String s_filepath = "C: // program files // Microsoft. NET // test.txt "; |
Equivalent
The following is a reference clip:
String s_filepath = @ "C:/program files/Microsoft. NET/test.txt "; |
2. Strings represented by @ can span several rows. It is convenient to write JS or SQL code in CS.
The following is a reference clip:
String s_multirows = @ "line1 Line2 Line3 "; String s_javascript = @" "; |
Usage in binary identifiers
In the C # specification, @ can be the first character of the identifier (Class Name, variable name, method name, etc.) to allow the reserved keyword in C # as its own defined identifier.
For example
The following is a reference clip:
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: Although @ appears in the identifier, it is not part of the identifier.
Therefore, the preceding example defines a class and contains a method named static and a parameter named bool.
This facilitates cross-language transplantation. Because a word is reserved as a keyword in C #, but it may not be in other languages.
Previous Article: Why is the size of an empty class not zero?
Next article: Slicing