Saturday, May 5, 2018

C# : What is difference between late binding and early binding in c#

Early Binding and Late Binding concepts belongs to polymorphism so let’s see first about polymorphism:

Polymorphism is an ability to take more than one form of a function means with a same name we can write multiple functions code in a same class or any derived class.

Polymorphism we have 2 different types to achieve that:
  • Compile Time also known as Early Binding or Overloading.
  • Run Time also known as Late Binding or Overriding.
Compile Time Polymorphism or Early Binding:
In Compile time polymorphism or Early Binding we will use multiple methods with same name but different type of parameter or may be the number or parameter because of this we can perform different-different tasks with same method name in the same class which is also known as Method overloading.

See how we can do that by the following example:

ASP.NET
Run Time Polymorphism or Late Binding:
Run time polymorphism also known as late binding, in Run Time polymorphism or Late Binding we can do use same method names with same signatures means same type or same number of parameters but not in same class because compiler doesn’t allowed that at compile time so we can use in derived class that bind at run time when a child class or derived class object will instantiated that’s way we says that Late Binding. For that we have to create my parent class functions as partial and in driver or child class as override functions with override keyword. 

Like as following example:

ASP.NET

No comments:

Post a Comment