Difference between early binding and late binding in C#

Hi All,
Please give me differential  points between early binding and late binding in c#.
thank you.
Last updated:1/26/2016 11:28:36 PM

2 Answers

Anupam Mishra
Anupam Mishra

Here, these two topics are closely related to one most useful concept of OOP i.e. Polymorphism. 
 Polymorphism means many forms (ability to take more than one form). In Polymorphism poly means “multiple” and morph means “forms” so polymorphism means many forms.
In polymorphism we will declare methods with same name and different parameters in same class or methods with same name and same parameters in different classes. Polymorphism has ability to provide different implementation of methods that are implemented with same name.
In Polymorphism we have 2 different types those are
     -   Compile Time Polymorphism (Called as Early Binding or Overloading or static binding)
     -   Run Time Polymorphism (Called as Late Binding or Overriding or dynamic binding)

Compile time polymorphism means we will declare methods with same name but different signatures because of this we will perform different tasks with same method name. This compile time polymorphism also called as early binding or method overloading.
Method Overloading or compile time polymorphism means same method names with different signatures (different parameters)
Run time polymorphism also called as late binding or method overriding or dynamic polymorphism. Run time polymorphism or method overriding means same method names with same signatures.

In this run time polymorphism or method overriding we can override a method in base class by creating similar function in derived class this can be achieved by using inheritance principle and using “virtual & override” keywords.
Here, some useful points of related then. These are:
1. Performance  will be better in early binding.
2. Application will run faster in Early binding, since no boxing or unboxing is done here but in late binding, we need type conversion as it will be decoded at run time.
3. Easier to write the code in Early binding, since the intelligence will be automatically populated .
4. Less chances of errors in early binding, as syntax is checked which flags error at compile time itself but for late binding there are chances of run time exceptions.
5. Late binding would support in all kind of versions, due to handing at run time.
Minimal impact of code in future enhancements, if late binding is used.

Sanat Shukla
Sanat Shukla

Early-Binding

Whenever use the Early-Binding, an object is assigned to a variable declared to be of a specific object type. The early-binding objects are basically a strong type objects or static type objects. Until, the Early-Binding, methods, functions and properties which are detected and checked during compile time and perform other optimizations before an application executes. Here, the huge advantage of using early binding is for performance and ease of development.

Common Examples:

  • ComboBox cboItems;
  • ListBox lstItems;

Late Binding

Into the late binding concept - As the name suggests that compiler does not know what kind of object it is, what are all the methods and properties it contains. We have to declare it as an object, later you need get the type of the object, methods that are stored in it. Often, everything will be known at the run time.

Common Examples:

  • Object objItems;
  • objItems = CreateObject("DLL or Assembly name");

Early Binding vs. Late Binding

These are some common features - 

  • The application will run faster in Early binding, since no boxing or unboxing are done here.
  • Its easier to write the code in Early binding, since the intellisense will be automatically populated
  • Here the minimal Errors in Early binding, since the syntax is checked during the compile time itself.
  • The Late binding would support in all kind of versions, since everything is decided at the run time.
  • That is the minimal Impact of code in future enhancements, if Late Binding is used.
  • The performance will be code in early binding.

Answer