Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

late binding 1

Status
Not open for further replies.

fmardani

Programmer
Jul 24, 2003
152
Hi,
Could you please explain why and where late binding is used in c# with a few examples?
Thanks
 
There are lot of examples.
Code:
private void menuItem1_Click(object sender, System.EventArgs e)
{
}
"sender" declared as object can point to data of any data type.
The object variable is always late bound.
A reference type variable is early bound if it is declared to be of a specific class, such as Button.
This allows the compiler to perform certain optimizations at compile time (type checking etc...).
At run time, when members oo an early-bound object variable are accessed,the compiler has already done a lot of work.
The CLR (Common Language Runtime) is required to perform type checking and member lookup at run time.
Another more complex late binding :
As you know, every assembly includes metadata information.
The standard interface to an assembly's metadata is encapsulated in the System.Reflection namespace.
To allow programmatic access to this information, the System.Reflection includes a class for each type of information in an assembly's metadata.
An application can crete instances of these classes as nedeed and then populate them with the apropiate information from a particular assembly.
Mainly, the classes in the System.Reflection can be used to create a hierarchical in-memory structure that contains an assembly's metadata.
With that, all classes, methods etc... in the assembly could be listed and called.
There is also the System.Reflection.Emit namespace which can be used to create dynamic assemblies, assemblies that are created directly in memory.
With this approach, a running application creates MSIL code and metadata, builds the assembly on the fly and then executes it. All here is late binding.
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top