Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
A base class, in the context of C#, is a class that is used to create, or derive, other classes. Classes derived from a base class are called child classes, subclasses or derived classes. A base class does not inherit from any other class and is considered parent of a derived class.
The base class forms the means by which inheritance is accomplished through derivation. A class derived from a base class inherits both data and behavior. For example, vehicle can be a base class from which the derived classes car and bus can be derived. Both car and bus are vehicles, and they each represent their own specializations of base class.
As in Java but unlike C++, C# does not support multiple inheritances of classes. C# differs from Java by explicitly marking a virtual modifier for all virtual members.
A base class is also known as a parent class or superclass.
Base class helps to create a specialized class that can reuse the code that is implicitly gained from the base class (except constructors and destructors) and extend the functionality of base class by adding or overriding members relevant to derived class in derived class. In C#, events are declared in base class that can be raised from derived classes. Generic classes that are used to encapsulate operations that are not specific to a particular data type serve as base classes, providing generic behavior so as to achieve flexibility and code reusability.
The key the properties of the base class in C#:
Although the base class and interface can be used interchangeably, classes are more flexible than interfaces from a versioning perspective. Base class is preferred in most cases except the following scenarios where: