. NET early binding and late binding (i)

Source: Internet
Author: User

The term "binding" is very common in life, like cell phone bindings, mailbox bindings, and so on. There are also "bindings" in. NET, such as types of bindings. In the process of machine room reconfiguration encountered a particularly interesting phenomenon: layer B calls the factory layer and interface to decouple it from the D layer, so the method in the B-layer class has written such a statement, taking the USERBLL class as an example:

    Public Function Login (Enuser as entity.userentity) as DataTable        ' instance chemical factory class CreateUser        Dim CreateUser as New Factory.createuser        ' creates Userimpl        Dim Iuser = CreateUser in the D layer dynamically through the factory. Produceuser ' Returns the DataTable object return        Iuser. Selectuser (enuser)   End Function

because there are multiple methods in the Userbll class, each method has a "dim createuser As New Factory.createuser" and a "dim Iu=createuser." Produceuser "These two lines of code, so that the duplicate code is used. So, I wrote these two lines of code that I used repeatedly, outside the method body,
    Dim createuser As New factory.createuser    ' creates userimpl    Dim Iuser = CreateUser In the D layer dynamically through the factory. Produceuser '       <summary> '    Verify login information ' </summary> '    <param name= ' Enuser ' > Entity userentity</param> '    <returns>DataTable</returns> '    <remarks></remarks > Public    Function Login (Enuser as entity.userentity) as DataTable        Return Iuser. Selectuser (enuser)    End Function

I thought there was no difference between this and the previous, but there were problems when writing other methods. When using IU in a method, you can't find a way to do it, halo .... But when the repetition of the two lines of code written in the method can be found, very puzzled about this matter, there is a picture of the card:

Two identical code written in a different position caused by the effect is really different, there is a wooden feel very interesting. Why can't I find its properties and variables when I use Iuser in a method after writing to the method body? In response to this problem, I have done a lot of ways to solve, after my various attempts, finally found a solution,

In contrast to the second and third diagrams, the same two lines of code written outside the method are just on the "dim iu= ..." basis, plus "dim iu as Idao." Iuser= ... " we'll find the properties and methods of the method when it calls IU, So what's the problem? In Sunday, 文斌 and I discussed this issue for a long time, and then query a lot of information, finally emperor. After an afternoon of battle, we finally found the key to the problem, which is what we want to say early binding and late binding. Take a look at the next article . NET early binding and late binding (ii)

PS: We can do this little experiment, especially interesting!


. NET early binding and late binding (i)

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.