Reputation: 23
Is there a way to declare a variable that has symbol involved? Such as:
int MIN% = 0;
or
string DE/M = "";
Upvotes: 2
Views: 787
Reputation: 8236
C# is based on the Unicode character set. You can include certain (many, in fact) symbols in identifiers. For example, the following is valid code that will compile:
int myΔ = 1;
myΔ++;
int \u0066 = 1;
\u0066++;
As to the specific examples given (%
, /
), both are illegal characters in identifiers (most likely because they have other meaning within the language as operators).
This article as well as the C# specification provide additional information.
Upvotes: 0
Reputation: 223257
See Variable Naming Rules - C#
The first character of a variable name must be either a letter, an underscore character (_), or the at symbol (@).
Subsequent characters may be letters, underscore characters, or numbers.
You can't have any special character other than _
in variable name, (OR @ symbol as the first character) - So there is no point escaping it.
Upvotes: 2