What is early binding and late binding?

Asked 07-Dec-2019
Viewed 1488 times

1 Answer


0

Concept Of Early Binding C# [.Net framework]

The early-binding means - methods, properties are detected and checked during compile time. There compiler knows about what kind of object it is.
Suppos that, a method or property does not exist or has a data type problems then the compiler automatically throws an exception during compile time.
Let us try to understand it's in briefly, the methods and properties which are detected and checked during compile time is called as early binding.
There objects are strongly typed objects or static objects. So, due to this reason the early binding improves the performance and ease of development.
And the application runs faster since there is no-type cast in early binding.  
The basic concept of early binding, its reduces the number of severity of run-time errors upfront before going it to runtime.
Example
System.IO.FileStream FS ;

FS = new System.IO.FileStream("C:\\temp.txt", System.IO.FileMode.Open);

Late Binding

Whenever an object is dynamic or not known which will only bind during runtime is called as Late binding. This is just an opposite of early binding. Into the late binding compilation, compiler does not know what kind of object or actual type of an object which contains methods & properties so it bypass the compile-time checking which was handled by run-time checking. Where the runtime handling or Late Binding objects are of dynamic types means actual type of an object is decided depending on data on right hand site which is possible dynamically during runtime only.
Basicly, the things that we can handle statically is done at early binding and things which can handled during dynamically only is done at late binding. We would suggest the best example for late binding will be reflection and dynamic keyword.
Example
class Program

    {
        static void Main(string[] args)
        {
            dynamic DynObj = 4;
            Console.WriteLine(DynObj.GetType());

        }
    }
What is early binding and late binding?