When an object is assigned to an object variable of the specific type, then the C# compiler performs the binding with the help of .NET Framework. C# performs two different types of bindings which are:
- Early Binding or Static Binding
- Late Binding or Dynamic Binding
It recognizes and checks the methods, or properties during compile time. In this binding, the compiler already knows about what kind of object it is and what are the methods or properties it holds, here the objects are static objects. The performance of early binding is fast and it is easy to code. It decreases the number of run-time errors.
prog.cs(34, 5): error CS1061: Type `Geeks’ does not contain a definition for `mymethod’ and no extension method `mymethod’ of type `Geeks’ could be found. Are you missing an assembly reference?
prog.cs(5, 7): (Location of the symbol related to previous error)
Explanation: In the above example, we have a class named as Geeks. This class contains details() method. Here, the compiler already knows about the properties and methods present in Geeks. But when we try to call mymethod() then it will throw an error because this method is not known by the compiler.
In late binding, the compiler does not know about what kind of object it is and what are the methods or properties it holds, here the objects are dynamic objects. The type of the object is decided on the bases of the data it holds on the right-hand side during run-time. Basically, late binding is achieved by using virtual methods. The performance of late binding is slower than early binding because it requires lookups at run-time.
Example: In the below, program the obj holds integer type data and obj1 holds double type data. But the compiler doesn’t resolve these at compile-time. At the runtime, these dynamic objects get detected and converted into
System.Double respectively. Thats why the run-time resolving process is termed as late binding.
The type of the objects are : System.Int32 System.Double
- Late Binding using Reflection in C#
- How to Install and Setup Visual Studio for ASP.NET?
- C# | .NET Framework (Basic Architecture and Component Stack)
- C# | Boxing And Unboxing
- Difference between SortedList and SortedDictionary in C#
- C# | TrimStart() and TrimEnd() Method
- C# | Class and Object
- C# | Check if SortedSet and a specified collection share common elements
- C# | Check if HashSet and the specified collection contain the same elements
- C# | Check if a HashSet and a specified collection share common elements
- C# | Check if SortedSet and the specified collection contain the same elements
- C# | Jump Statements (Break, Continue, Goto, Return and Throw)
- Difference between Managed and Unmanaged code in .NET
- C# | Bitwise AND between the elements of BitArray
- C# | Add key and value into StringDictionary
- C# | Add the specified key and value into the ListDictionary
- C# | Adding the specified key and value into HybridDictionary
- C# | Add key and value into OrderedDictionary collection
- C# | Insert into OrderedDictionary with key and value at specified index
- C# | Nesting of try and catch blocks
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.