According to msdn Enums cannot have a base type of char. Why can enums not have a base type of char? Also why does microsoft strongly recommend that an enum contain a constant with a value of 0? Thank you very much
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can find a link to the C# language specification. I think the reason for the restriction probably derives from these statements in the language specification, section 4.1.5.
The char type is classified as an integral type, but it differs from the other integral types in two ways:
There are no implicit conversions from other types to the char type. In particular, even though the sbyte, byte, and ushort types have ranges of values that are fully representable using the char type, implicit conversions from sbyte, byte, or ushort to char do not exist.
Constants of the char type must be written as character-literals or as integer-literals in combination with a cast to type char. For example, (char)10 is the same as ‘\x000A’.
As far as why zero, because the default value of an uninitialized
enumis 0.