Inheritance

System.Object

We mentioned previously that types using inheritance form a tree-like concept known as an inheritance hierarchy. What is important here, is that all trees have a root, and in the .NET word, that root is System.Object.

using System; public class Program { ...

 

In our example above, not only have we declared an a variable named root, of type Object, but we're actually also implicitly inheriting from Object for our Program class. Effectively, the following declarations are the same:

public class Program
{
}

public class Program : Object
{
}

You don't need to explicitly specify Object as this will be enforced by the compiler.

What this means, is that every class you create has a root, and that root is System.Object. Object is also an alias of object which means you can use both forms interchangeably.

The System.Object type also defines core methods which are used throughout the framework, including ToString(), GetHashCode() and Equals(object). You'll see in the next concept how methods can be created on base classes and used on derived classes.

Page 4 of 18