What characters are allowed and what is not allowed in a C# class name? Could you please help?
EDIT: To specify. What special characters are allowed? Please be specific, because links to 50 pages specs in high-technical language is not an answer that will help me a lot.
EXPLANATION: What I try to accomplish is to divide class name into distinguishable parts for example:
class Person@WorkOffice@Helper@Class
{
}
And I think about a way of using some kind of character or something else to be able to get parts Person, WorkOffice, Helper and Class from this class name.
And yes, I know it's crazy, but I need it that way. I know that I can use attributes and reflection to store this data in class meta but this is not the case, so please don't suggest this solution.
A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores. The first letter of an identifier should be either a letter or an underscore.
We have 256 character to represent in C (0 to 255) like character (a-z, A-Z), digits (0-9) and special character like !, @, # etc. This each ASCII code occupied with 7 bits in the memory. Let suppose ASCII value of character 'C' is 67. When we give input as 'B' machine treat it as 67 internally and stores its address.
The C character set consists of upper and lowercase alphabets, digits, special characters and white spaces. The alphabets and digits are altogether called as the alphanumeric character. A variable is an entity that has a value and is known to the program by name.
The C rule of declaring variable name says that variable name starts with the underscore but not with other special characters, but $ can also be used right.
The spec details are here. Essentially, any unicode character (including unicode escapes) in the character classes Lu, Ll, Lt, Lm, Lo, Nl, Mn, Mc, Nd, Pc, and Cf. The first character is an exception and it must be a letter (classes Lu, Ll, Lt, Lm, or Lo) or an underscore. Also, if the identifier is a keyword, you must stick an @ in front of it. The @ is optional otherwise.
Valid identifiers in C# are defined in the C# Language Specification, item 9.4.2. The rules are very simple:
source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With