Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How int is the backing type for enum

Tags:

According to this post int is the backing type for enum.

When I check the source code of .NET System.Enum abstract class inherits from System.ValueType abstract class.

But when I check the System.Int32 struct it inherits from interfaces but not from System.ValueType.

On the contrary, when I decompile mscorlib.dll and check the Int32 struct it says that the struct has base type of System.ValueType.

enter image description here

But still checking the decompiled source code I can not see anything about System.ValueType.

enter image description here

It makes me think that the struct keyword makes the declaration auto-Sytem.ValueType, which Microsoft also denotes in this reference.

But I still have a question. As far as I know, inheritance of two different classes from the same parent does not imply that one also inherits from other. I mean if B:A and C:A this does not always mean that C:B.

Also, when I check the source code, System.Enum has quite a different implementation to that of System.Int32.

So, under these circumstances, how does this fit with 'System.Int32' being the backing type for System.Enum?

Can anyone explain?


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!