. NET early binding and late binding (ii)

Source: Internet
Author: User

The previous article introduced. NET in the context of the story, at the end of the article leads to "early binding and late binding", then this article is targeted. NET in a simple introduction to the binding custom.

Early bindingearly binding: If. Net is able to know the object that the property or method belongs to at compile time, you can pre-locate the DispID or vtable address of that member in the type library. This eliminates the need to invoke GetIDsOfNames at run time. When a class of a variable is explicitly declared, such as as class, the variable can only hold a reference to the object of that class.. Net can use early binding for all the properties and methods that the variable calls.
Late bindingthere is a base class object in. NET, and all classes inherit from the base class when we declare a variable without specifying the variable's type. NET declares the variable as an as Object. NET at compile time cannot determine which type of object the variable will reference. Therefore,. Net must use late binding, at run time to determine whether the object's properties and methods can use the variable.
Once you know the early binding and late binding, look at our code:

    ' Late binding with object type '      Dim IU = CreateUser. Produceuser      ' early bound, whose object type is Iuser     Dim iu as Idao. Iuser=createuser. Produceuser  
object types of variables in the program:


Early Period binding We have been re-use, still remember the VB variant (variable type), that is the earliest we started to contact a late binding, and now we are in the machine room used in the generics, which also involves the late binding.

the difference between early binding and late binding

Early binding: Early bound objects are much faster than late-bound objects and can make code easier to read and maintain by declaring the kind of objects they use. Another advantage of early binding is that it enables useful features such as automatic code completion and dynamic Help, because the Visual Studio integrated Development Environment (IDE) can determine exactly what type of object you are using when you edit your code. Because early binding allows the compiler to report errors when compiling a program, it reduces the number and severity of run-time errors.

Late binding: Late binding, when a property or method is called, Visual Basic passes the member name to the GetIDsOfNames method of the object's IDispatch interface. GetIDsOfNames returns the member's dispatch ID, or DISPID. Visual Basic then passes the DispID to the IDispatch interface's Invoke method to invoke the member. For out-of-process parts, this means an extra cross-process method call, with the result that the call overhead doubles.

Summarysmall problems contain great wisdom, understanding that early binding and late binding in our future programming should be used cautiously. Did anyone notice that in the previous article, we used late binding in the method body to get the variable's member variable, because. There is a mechanism for type inference in net. On the type of reasoning, you can check the Internet on this aspect of knowledge, here is not introduced ... PS: Will not be the driving force to find the problem, continue to maintain ...

. NET early binding and late binding (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.