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.Componen tModel.IBinding List
....
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 5 1933
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.myp rop
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.ToStr ing)
' however, you cannot directly access the protected
' method via the object. hence, the line below wont
' even compile.
' messagebox.show (o1.prop.ToStri ng)
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*****@ingeni um-tech.com> wrote in message
news:O7******** ******@TK2MSFTN GP12.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.Componen tModel.IBinding List ... 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
Thanks for the clarification Imran.
Harold
"Imran Koradia" <no****@microso ft.com> wrote in message
news:Od******** ******@TK2MSFTN GP09.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.myp rop 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.ToStr ing) ' however, you cannot directly access the protected ' method via the object. hence, the line below wont ' even compile. ' messagebox.show (o1.prop.ToStri ng) 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*****@ingeni um-tech.com> wrote in message news:O7******** ******@TK2MSFTN GP12.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.Componen tModel.IBinding List ... 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
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.t heMethod" 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****@microso ft.com> wrote in message
news:Od******** ******@TK2MSFTN GP09.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.myp rop 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.ToStr ing) ' however, you cannot directly access the protected ' method via the object. hence, the line below wont ' even compile. ' messagebox.show (o1.prop.ToStri ng) 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*****@ingeni um-tech.com> wrote in message news:O7******** ******@TK2MSFTN GP12.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.Componen tModel.IBinding List ... 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
Ahh..I see...thanks Jay!
Harold
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:eR******** ******@TK2MSFTN GP10.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.t heMethod" 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
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******** ******@TK2MSFTN GP10.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.t heMethod" 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****@microso ft.com> wrote in message news:Od******** ******@TK2MSFTN GP09.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.myp rop 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.ToStr ing) ' however, you cannot directly access the protected ' method via the object. hence, the line below wont ' even compile. ' messagebox.show (o1.prop.ToStri ng) 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*****@ingeni um-tech.com> wrote in message news:O7******** ******@TK2MSFTN GP12.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.Componen tModel.IBinding List ... 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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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. It's very annoying. Is there
any way around it?
What I need is something like AutoNumber, *except* I want the values to be
unique across six different tables. Any ideas?
Unknown function <name> in validation expression or default value...
|
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 at -1 and 0 respectively.
Unless I specifically set the table field's defaultvalue
to Null, the form comes up with an automatic value
of 0 in the control? The control has NO default
value property setting. Why is that?
|
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 = new MyClass();
c = "my text";
In the line above, the string is assigned to a field in the class instance.
|
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 field properties is of type "Field", so we have eg.
__property Field* get_Code( );
__property Field* get_Name( );
|
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 following default properties: Height =
32px, Width = 144px.
I declare the Width property in my control as...
\\\
| |
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 fld.Properties("Caption") <"" then
do something
The problem is that all fields are included, even those with no caption set.
I've tried IsMissing, IsEmpty and IsNull for the test but none will filter
|
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
Set(ByVal Value As Image)
|
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 "Save As" dialog and the ability to grab the filepath so that the second export appends to it.
Anyway, I found Microsofts method and it works, except that I can't figure out how to populate the File Name box in the Dialog with a default name (say,...
|
by: puzzlecracker |
last post by:
/*1 not specified*/class {
/*2 not specified*/ void Foo(){}
}
Will they, like in c++, default to private?
Thanks
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |