Delegation vs Inheritance in C#

Delegates in C#

A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.

To declare a delegate.

delegate <return type> <delegate-name> <parameter list>

Delegation has run-time flexibility i.e. you can easily change it at runtime. The instance you create in Delegation is of a known class.

Inheritance in C#

Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and speeds up implementation time.

When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.

This is how we create a base and derived class in Inheritance.


<access-specifier> class <base_class> {
class <derived_class> : <base_class> {
Samual Sam
Samual Sam

Learning faster. Every day.