© Mikael Olsson 2018
Mikael OlssonC# 7 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-3817-2_11

11. Inheritance

Mikael Olsson1 
(1)
Hammarland, Länsi-Suomi, Finland
 
Inheritance allows a class to acquire the members of another class. In the following example, the class Square inherits from Rectangle , specified by a colon. Rectangle then becomes the base class of Square, which in turn becomes a derived class of Rectangle. In addition to its own members, Square gains all accessible members in Rectangle, except for any constructors or destructors.
// Base class (parent class)
class Rectangle
{
  public int x = 10, y = 10;
  public int GetArea() { return x * y; }
}
// Derived class (child class)
class Square : Rectangle {}

Object Class

A class in C# ...

Get C# 7 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.