© Mikael Olsson 2020
M. OlssonC# 8 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-5577-3_11

11. Inheritance

Mikael Olsson1 
(1)
HAMMARLAND, 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# may only inherit ...

Get C# 8 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.