Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Where's BeginInit

Back to Forum: Tech Off
  • User profile image
    JoshB

    Alright darn it, I'm admitting defeat again.

    The windows forms designer will call BeginInit on controls while initializing them, but it casts to ISupportInitialize first.

    (Control1 as ISupportInitialize).BeginInit();

    However, there is no BeginInit on Control1, calling Control1.BeginInit fails.

    I was under the impression that for Control1 to be able to support the interface ISupportInitialize, it would have to have the BeginInit method.

  • User profile image
    stevo_

    This is the difference between explicit and implicit implementations of an interface member.. by default you'll be used to implicit implementations, where your class has a public member that matches the signature of the member the interface requires. This way the method will appear when cast as your class..

    But equally you can do explicit implementations of a member, where the member will only appear when the object is cast as the interface (as being done in your code sample above)..

    In c# you do explicit implementations like this:

    class MyClass : ISupportInitialize
    {
      void ISupportInitiailize.BeginInit()
      {
      } }
    vs
    class MyClass : ISupportInitialize
    {
    public void BeginInit()
    {
    }
    }

    Interface members must be public so if you do them as private or protected in vb then its really just doing an explicit implementation that calls the private or protected one (or at least marks the private or protected member as being the explicit implementation for this interface member).

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.