I've found this all over the place in this code:
public enum Blah: int { blah = 0, blahblah = 1 }
Why would it need to inherit from int? Does it ever need to?
Enums cannot inherit from other enums. In fact all enums must actually inherit from System.
Nope. it is not possible. Enum can not inherit in derived class because by default Enum is sealed.
You cannot have an enum extend another enum , and you cannot "add" values to an existing enum through inheritance.
An enum is a special "class" that represents a group of constants (unchangeable/read-only variables).
According to the documentation:
Every enumeration type has an underlying type, which can be any integral type except char. The default underlying type of the enumeration elements is int.
So, no, you don't need to use int. It would work with any integral type. If you don't specify any it would use int as default and it's this type that will be used to store the enumeration into memory.
Enums are implicitly backed by integers.: int
just restates the default, just like void M();
vs. private void M();
.
You can also create enums that are backed by other intergral types, such as enum GiantEnum : long
.
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