I was kind of shocked by this. Could someone explain why this works? A good example of when to use it would also be nice.
Public Interface IFoo
Sub DoIt()
End Interface
Public Class Bar
Implements IFoo
Private DoIt() implements IFoo.DoIt
End Class
...
Dim b as new Bar()
b.DoIt() 'error
CType(b, IFoo).DoIt() 'no error
Having a private interface implementation basically just allows you to implement an interface without having to muddy your class' API. You can implement IFoo
, but only APIs that treat you as an IFoo
need to know that.
MSDN says
You can use a private member to implement an interface member. When a private member implements a member of an interface, that member becomes available by way of the interface even though it is not available directly on object variables for the class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With