It is true in .NET that all types inherit from System.Object.
What I find paradoxical, is a few methods on System.Object - namely
- public virtual string ToString();
- public virtual bool Equals(object objA, object objB);
System.String is inherited from System.Object:
[Serializable]
public class String : Object { /*...*/ }
System.Boolean is inherited from System.Object:
[Serializable]
public struct Boolean : Object { /*....*/ }
What is the going on under the covers that allowed the System.Object class to allow sub-classes to be used as return types on its methods? How did this code ever compiled, as there seems to be a circular references. String <-> Object <-> Boolean.
I'm sure I will see statements, on "thats how it is implemented", but I can understand if these return types were "System.Object"'s themselves, and then a sub-class used the implemenations of string, bool and other System.ValueTypes to declare a new base class.
I hope that makes sense.
Thanks in advance,
Dominic