- By default, the first value of the enumeration is 0, which can be explicitly assigned to the enum.
- You can define the base type of the enum, such as enum E : short {}, sizeof(E) == 2; int by default.
- Enumerated inheritance chain: ValueType->Enum->enum
- The conversion between the enum type and the base type is explicit, except for 0, because there is an implicit conversion from 0 to any enum type.
- The enum's ToString() outputs the identifier of its enum value,
- From string to enumeration: AEnumType a = (AEnumType) Enum.Parse(typeof(AEnumType), "flag"); may fail, and the code should include exception handling mechanisms.
- You can use Enum.IsDefined() to check if a value is included in an enum.
if (! Enum.IsDefined(typeof(SearchMode), options)) throw new ArgumentException(Properties.Resources.InvalidEnumerationValue, "options");
SearchMode is an enum type, if the passing options value is not within the scope of this enum definition,For example, if an enum defines 1,2, and options are from 3 casts, then the IsDefined method returns false.
|