kota's memex
public class Manager : Employee
{
    // Employee fields, properties, methods and events are inherited
    // New Manager fields, properties, methods and events go here...
}

A class in C# can only directly inherit from one base class. However, because a base class may itself inherit from another class, a class might indirectly inherit multiple base classes.

When a class inherits from another 3 things happen:

object base class

Every class you define, by default, has a base class called object. It has a few methods such as ToString and Equals.

This also means you can use any class wherever the object class is required. It will however, be treated as object, not as whatever class you assigned:

object thing = new Point(2, 4);
Console.WriteLine(thing.ToString()); // Safe
Console.WriteLine(thing.X); // Compiler error

constructors

A derived class does not inherit constructors from its parent. However, you can leverage the constructors from the parent:

public class GameObject
{
  public GameObject(float posX, float posY, float velX, float velY)
  {
    _posX = posX; _posY = posY;
    _velX = velX; _velY = velY;
  }
}

public class Asteroid : GameObject
{
  public Asteroid() : base(0, 0, 0, 0) // Giving parameters to base constructor.
  {
  }

  public Asteroid(
    float posX,
    float posY,
    float velX,
    float velY,
  ) : base(posX, posY, velX, velY) // Passing parameters to base constructor.
  {
  }
}

casting from parent to child

If you are certain of the object's type:

GameObject obj = new Asteroid();
Asteroid asteroid = (Asteroid)obj;

If you need to check the object's type:

if (obj.GetType() == typeof(Asteroid)) {
  // Do stuff.
}

as keyword

You can shorted the above type casting with the as keyword:

Asteroid? asteroid = obj as Asteroid;

If the type cast fails, asteroid will be null.

is keyword

Finally, the is keyword works similarly to as, but returns a boolean:

if (obj is Asteroid asteroid)
{
  // Do stuff with asteroid.
}

// Or if you don't need the asteroid variable:
if (obj is Asteroid)
{
}