C# Inheritance

Today I’m talking about C# class inheritance and why it’s important and incredibly useful to know how to use it efficiently.

Vincent Taylor
Aug 31, 2021
How to inherit/create an inheriting class

Class Inheritance is a fundamental feature of Object-Oriented Programming languages which allows you to create base classes and derived classes. Derived classes can reuse, extend upon, and override the code in its base class.

Car, Truck, and Motorcycle inherit (or derive) from the base class Vehicle, so they can use its public and protected variables and functions

Inheritance allows you to put variables and functions that need to be in multiple classes, into one single class, but allow them to be accessible from other classes.

Classes can only inherit from one other class, however, if you for some reason need to derive from multiple scripts, there is another option. Interfaces are similar to classes, and classes can inherit from multiple interfaces. I’ll cover Interfaces in another Medium post in future.

--

--

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.