473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

default access type of property?

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

Nov 21 '05 #1
5 1915
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

Nov 21 '05 #2
Thanks for the clarification Imran.

Harold

"Imran Koradia" <no****@microsoft.com> wrote in message
news:Od**************@TK2MSFTNGP09.phx.gbl...
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


Nov 21 '05 #3
Imran & Harold,
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. The C# (& Java & C++) compiler implicitly associate a method in the class
with a method in the Interface by matching on name & signature.

The VB compiler explicitly associates a method in the class with a method in
the Interface via the Implements keyword.

This allows the name & scope to be anything you want in VB.NET, while in C#
(& Java & C++) it has to be public & the same name.

C# does allow you to use "Explicit interface member implementation" where
you don't give a scope and name the method "theInterface.theMethod" in the
implementing class, VB.NET accomplishes the same thing via the Implements
keyword (by allowing you to name this method anything you want & changing
the scope).

I prefer the VB.NET way of implementing interfaces over the C# method, as
its more flexible!

Hope this helps
Jay

"Imran Koradia" <no****@microsoft.com> wrote in message
news:Od**************@TK2MSFTNGP09.phx.gbl... 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


Nov 21 '05 #4
Ahh..I see...thanks Jay!

Harold

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eR**************@TK2MSFTNGP10.phx.gbl...
Imran & Harold,
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. The C# (& Java & C++) compiler implicitly associate a method in the class
with a method in the Interface by matching on name & signature.

The VB compiler explicitly associates a method in the class with a method

in the Interface via the Implements keyword.

This allows the name & scope to be anything you want in VB.NET, while in C# (& Java & C++) it has to be public & the same name.

C# does allow you to use "Explicit interface member implementation" where
you don't give a scope and name the method "theInterface.theMethod" in the
implementing class, VB.NET accomplishes the same thing via the Implements
keyword (by allowing you to name this method anything you want & changing
the scope).

I prefer the VB.NET way of implementing interfaces over the C# method, as
its more flexible!

Hope this helps
Jay

Nov 21 '05 #5
Jay,

Thanks for the clarification. I have no experience at all with C# (or rather
haven't really bothered to look in that direction :)). That definitely
explains the OP's situation.

Imran.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eR**************@TK2MSFTNGP10.phx.gbl...
Imran & Harold,
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. The C# (& Java & C++) compiler implicitly associate a method in the class
with a method in the Interface by matching on name & signature.

The VB compiler explicitly associates a method in the class with a method

in the Interface via the Implements keyword.

This allows the name & scope to be anything you want in VB.NET, while in C# (& Java & C++) it has to be public & the same name.

C# does allow you to use "Explicit interface member implementation" where
you don't give a scope and name the method "theInterface.theMethod" in the
implementing class, VB.NET accomplishes the same thing via the Implements
keyword (by allowing you to name this method anything you want & changing
the scope).

I prefer the VB.NET way of implementing interfaces over the C# method, as
its more flexible!

Hope this helps
Jay

"Imran Koradia" <no****@microsoft.com> wrote in message
news:Od**************@TK2MSFTNGP09.phx.gbl...
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



Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ed Havelaar | last post by:
I have a cool function that I want to use as a default value for a column in my table. But I can't because apparently Access doesn't allow user defined functions in expressions for default values....
10
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued...
5
by: Chuck Bowling | last post by:
Maybe I'm doing something wrong or just don't understand the concept, but i'm having a problem with default properties. My impression of how a default property should act is this; MyClass c =...
1
by: kevin_g_frey | last post by:
Hello All, I have an MC++ class named "Person" which encapsulates access to a database entity and it contains a number of field properties eg. Code, Name, Address, Suburb etc. Each of the...
3
by: Marty McFly | last post by:
Hello, I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the...
6
by: Bob Darlington | last post by:
I want to use the caption property for fields in a recordset as a condition in a loop. That is, I only want to consider those fields which have captions: For each fld in RecordsetName.Fields If...
9
by: Eric | last post by:
Hi Everyone, I'm writing a UserControl that exposes a property of the type System.Drawing.Image, like this: Public Property DefaultImage() As Image Get Return propDefaultImage End Get...
2
by: vbaDev | last post by:
Hi. I am using Access 2000 and in my code I'm exporting a table into an Excel file (creating it), then the code needs to export another query into the same file (a new worksheet). So I needed both a...
8
by: puzzlecracker | last post by:
/*1 not specified*/class { /*2 not specified*/ void Foo(){} } Will they, like in c++, default to private? Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.