MSDN defines System.Enum as an abstract class:
[SerializableAttribute]
[ComVisibleAttribute(true)]
public abstract class Enum : ValueType, IComparable, IFormattable, IConvertible
And also MSDN make such statement about abstract class:
An abstract class cannot be instantiated. The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share.
But I simply cannot derive from System.Enum. According to Jeffery Richter in his book "CLR via C#", it is C# compiler that forbid that derivation.
And I checked System.Enum's members, most of them are static, which is reasonable for it cannot be instantiated and static methods don't need an object instance to invoke. But there are also some instance methods, such a GetHashCode() and GetTypeCode().
So, my first question is, if System.Enum cannot be instantiated or derived, how could these instance methods be invoked? Isn't this some kind of a paradox?
I know I could use the following approach to invoke these instance methods, but why? Is there some kind of System.Enum or derived type object instance created? When? and by whom?
public enum Days:byte { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday };
Days d = Days.Friday;
d.GetTypeCode();
d.GetHashCode();