Why does this declaration,
public enum ECountry : long { None, Canada, UnitedStates } require a cast for any of its values?
long ID = ECountry.Canada; // Error Cannot implicitly convert type 'ECountry' to 'long'. // An explicit conversion exists (are you missing a cast?) And is there a way to get a long value directly from the enum, besides casting?
This would not work either, for example:
public enum ECountry : long { None = 0L, Canada = 1L, UnitedStates=2L }
enumis to supportFlagsenumerations that have more than 32 items. You can use it to store randomlongvalues as well, but that's less common and kind of a bad idea.