Instructions
By using the '@' symbol we can use reserved keywords as variables/fields.
- //Using @ for variable names that are keywords.
-
- var @object = new object();
- var @string = "Sumit";
- var @if = Factor();
This is not only the problem we can solve with the '@' symbol. Let's try with the following example.
Verbatim string
A String can be created as a verbatim string. Verbatim strings start with the '@' symbol. The C# compiler understands this type of string as verbatim. Basically, the '@' symbol tells the string constructor to ignore escape characters and line breaks.
In the following example, the code compiler gives an error of "Unrecognized escape sequence." We can solve this issue with '\\' or the '@' symbol.
Example
- String Str1 = "";
- Str1 = "\Root\Key\NewFolder";
Solution :
- Str1 = "\\Root\\Key\\NewFolder";
- OR
- Str1 = @"\Root\Key\NewFolder";
Happy Coding :)