-
While reading ECMA 335 I noticed that in I.8.5.2
However if i run Anybody can help me what I'm missing here. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Because of strong typing: enum inherits from 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
|
Beta Was this translation helpful? Give feedback.
Because of strong typing: enum inherits from
Enum
class whileInt32
inherits fromValueType
. Moreover, some methods behave differently. For instance,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
andUInt32
. Both contain 4-bytes long data, but behave differently.IsAssi…