Dynamic and Static Binding in C#

Dynamic and Static binding in C#

Static and dynamic binding are two concepts of programming languages, which are used while working with functions. In overloading and overriding our compiler need to link and bind function and run the program.

So in static binding the function is linked at compile time and so that it’s also called early binding.

In Dynamic binding the function linked at run time and so that it’s also known as late binding.

Static binding can be performed using two possible ways which are following:

  • Function overloading
  • Operator overloading

In static binding compiler decides which function should run at compile time?

Dynamic binding can be performed using Polymorphism in which we use:

  • Function overriding

In this type of binding, function to be called is determined at runtime.

Function Overloading:

In this technique, we have many functions with the same name but different data types and sometimes different numbers of parameters. When we execute the code, the compiler decides at compile time that which function should be called.


Function Overriding:

It is much similar to overloading as it also has many functions with the same name but this time, their parameter’s count and data type are also same, but they are defined in different scope.

The function overloading can be done using abstract classes and virtual functions, and the classes must be inherited from each others.

In this technique, we use a concept of object oriented programming called polymorphism, which allow us to call function many times using a different scope, so we have three types of function’s scope in C#.

  • Virtual function
  • Override function
  • New function.

The parent class should use the virtual keyword with his function name so that the child class will able to define the function of the same name within its scope.



See also Function Overloading and overriding in Java