Labels

.

Tuesday, 18 June 2013

Late binding and Early binding in c#

This is very common question for interview so read carefully before attend the interview.It's related to OOPS concepts .

Early Binding :-

1 - 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.

2- Early binding is also known as compile time polymorphism, static binding and static typing.

3 - 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.

4 - Non-virtual methods are always early bound

5 - Early bound just means the target method is found at compile time, and
code is created that will call this. Whether its virtual or not (meaning
there's an extra step to find it at call time is irrelevant). If the
method doesn't exist the compiler will fail to compile the code.

1 - Late bound means the target method is looked up at run time. Often the
textual name of the method is used to look it up. If the method isn't
there, bang. The program will crash or go into some exception handling
scheme at run time.

2 - Late binding is also known as Run time polymorphism, Dynamic binding .

3 - Calling methods using reflection is an example of late binding. We write
the code to achieve this as opposed to the compiler. (E.g. calling COM
components.)

4 - Virtual methods are always late bound

5 - By using late binding in C# you cannot determine the error at compile time because compile time does not have any information about assembly type