All c types are derived from Object types

  • 2020-05-07 20:18:56
  • OfStack

CLR requires that each type eventually derive from the object type, as follows:
class Typer {} === class Typer: object {}

The top is exactly the same.

All types eventually derive from object, and each type has a basic set of methods:

Equals: returns True if two objects are equal
GetHashCode: returns a hash code for the value of the object
ToString: returns the full name of the type by default. Types such as int are overridden
GetType: returns the type of the object invoked

In addition, a protected method can be accessed from an object derived type

MemberWiseClone: returns a new real class
Finalize: virtual method, called before the memory reclaim

CLR requires all objects to be created using the NEW operator:

1. Compute types and all their base types, plus 1 additional member
2. Allocates the number of bytes required for the specified type from the heap
3. Call the instance constructor of the type to which any arguments specified in the call to New are passed.

Each type constructor, when invoked, is responsible for initializing the instance fields defined by this type, and ultimately calling object's constructor.

After new is executed, a reference to the new object is returned.

Related articles: