What is the data type - string[] @string ?
- tenarray of strings !!! - Grundy
2 answers
What you wrote is a declaration of a variable or a field with the type “array of strings” ( string[] ) and the name string . Since string is a keyword, in order to use it as a variable / field name, you must use @ before the identifier. Hence the form @string .
The @"text" form that appeared in the comments is another thing. This sets a string (more precisely, a string literal) in which there is no interpretation of \ as a special character (but there is a special interpretation of the sequence "" ). As a result, the following lines:
"C:\\Program Files\\WinRAR\\WinRAR.exe" and
@"C:\Program Files\WinRAR\WinRAR.exe" exactly the same.
If there is no \ in your line, then the @ -form is not needed (although it doesn’t hurt). Well, or needed, if your text inside the quotes is generated by some program, and not written manually.
- I would say not "necessary", but "possible." After all, you can write a
_string. - andreycha - @andreycha That is, it is correctly written string [] vsSource = new string [1]; vsSource [0] = @ "attribute vec2 coord; void main () {gl_Position = vec4 (coord, 0.0, 1.0);}"; - SVD102
- one@ SVD102, oooo :-) looks like a question about something else altogether :-) - Grundy
- one@ SVD102, verbatim string literal . And yes, this is a normal entry. Although specifically in this example, there is no difference to use
@or not - Grundy - @andreycha: Well, if for some reason you need the field to be called
string... For example, a convention for reflection. Or maybe this is a public property that implements the interface. - VladD
C # contains a large number of reserved words that should not be used as identifiers. However, you can use them. By name it can be stated that the identifier is taken "literally", i.e. not interpreted by the compiler. String [] -> array definition, and @string -> array name.