In the msdn spec, I could notice that System.Object
is the ultimate base class in .Net.
They say that System.ValueType
is an abstract class inheriting from System.Object
and overrides the methods like Equals
, Compare
etc...
Value types like bool
, int
etc.. inherit from System.ValueType
all the other .net objects inherits from System.Object
.
I have 2 questions on this.
- What is the need of System.Object? Why wasn't an interface preferred over here?
Am assuming it has only 2 direct Children(ignoring that we can create more) which is System.ValueType and System.ReferenceType both having entirely different implementations.
**Edit:**There is no System.ReferenceType. There is only Sytem.Object and Sytem.ValueType (overriding the base class).
Apologies here.
So System.Object may be needed to handle the basic CLR functionalities like object creation using new(), enforcing default constructor, GC etc ?
- When I de-compile
Sytem
dll, and see the implementation of bool, I just see a struct.
For a class (say Exception) I don't see the inheritance to System.ReferenceType or System.Object. How is this inheritance handled ?
Infact, what is Common Type System doing toMyCustomClass
to make it inherit fromSystem.Object
(since the inheritance is determined at compile time am thinking CTS is doing it)
Please feel free to correct me/edit the post if my understanding is wrong.