No access modifier can be specified for methods/properties in an interface.
If you access the property/method through the interface, you will always be
able to access the property/method even if the property/method is declared
private as long as you can Dim a variable of that interface (By casting the
object of the implementing class to this variable - this was the only way
one could access interface methods in VB6) . If you directly access the
property/method from the object that implements the interface, then the
access level is determined by the access modifier specified for the
property/method in the class.
here's what I mean:
interface myinterface
function myprop() as boolean
end interface
class class1
implements myinterface
protected function prop() as boolean implements myinterface.myprop
return true
end function
end class
sub test()
dim o1 as new class1
o = o1
' although the prop method is declared protected,
' you can still access it via the interface
messagebox.Show(o.myprop.ToString)
' however, you cannot directly access the protected
' method via the object. hence, the line below wont
' even compile.
' messagebox.show(o1.prop.ToString)
end sub
However, I'm not sure why would there be a difference between the C# and VB
compilers. Maybe thats the way MS intended it to be.
hope that helps..
Imran.
"Harold Hsu" <ha*****@ingenium-tech.com> wrote in message
news:O7**************@TK2MSFTNGP12.phx.gbl...
Hi all,
What's the default access type of a property declared in an interface?
The one I'm looking at is IBindingList:
Public Interface IBindingList
...
ReadOnly Property AllowEdit As Boolean
...
End Public
I have a class that implements IBindingList, but AllowEdit is implemented
as Protected:
Protected ReadOnly Property AllowEdit() As Boolean Implements
System.ComponentModel.IBindingList
...
End Property
If there is a method that takes an object implementing IBindingList as an
argument, wouldn't accessing AllowEdit causes an error? Why doesn't the
VB compiler complains when AllowEdit is implemented as Protected (or even
Private)? The C# compiler does complain. What am I missing here?
Thanks in advance,
Harold