Skip to content
Discussion options

You must be logged in to vote

Because of strong typing: enum inherits from Enum class while Int32 inherits from ValueType. Moreover, some methods behave differently. For instance,

Console.WriteLine(EnvironmentVariableTarget.User.ToString());
Console.WriteLine(1.ToString());

The binary representations of both values are same, that's why cast or coercion is not needed. That is, at IL and machine code level there is no differences between them. However, event C# requires the cast because the cast changes the type. The type in OOP is not only the data encapsulated by the instance but also the behavior. That's why you need that cast. Just like Int32 and UInt32. Both contain 4-bytes long data, but behave differently.

IsAssi…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AnakinRaW
Comment options

Answer selected by AnakinRaW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants