Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
In C#, early binding is a process in which a variable is assigned to a specific type of object during its declaration to create an early-bound object. This contrasts the late-bound object process, where an object type is revealed at the time of instantiation.
Early binding is implemented in a number of C# concepts, such as overloaded methods, overloaded operators and overridden methods, which are directly called via the use of derived objects. Early binding is not flexible and can result in version compatibility issues, due to the high dependency of property and method types and parameters.
Early binding is also known as compile time polymorphism, static binding and static typing.
Early binding benefits include:
During early binding, the C# compiler performs syntax and type checks to ensure that the correct parameter amount and type are passed to the method or property. Early binding also checks for the return value, which minimizes execution time and runtime errors.
For example, a C# automation client application needs to calculate a value with a defined Microsoft Excel formula. The application may create an object of type Microsoft Excel and call its required method after initializing the object properties. Because Microsoft Excel is a specific type of object, the created and assigned variable is an early-bound object.
While working with early-bound objects, it is necessary to include the type library where the definitions of early-bound object types are defined. Additionally, an early-bound object cannot be used to assign an object of another type after its declaration.