473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overriding private interface property?

Why does this work:

using System;

namespace ConsoleApplicat ion1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DerivedClass d=new DerivedClass();

d.MyProp=10;
Console.WriteLi ne(d.MyProp.ToS tring());
}
}

public class DerivedClass : BaseClass, IAbClass
{
#region IAbClass Members

public override int MyProp
{
get{return base.MyProp;}
set{base.MyProp =value;}
}

#endregion
}

public class BaseClass : AbClass
{
}

public abstract class AbClass : IAbClass
{
private int _nAb;
#region IAbClass Members

public virtual int MyProp
{
get{return _nAb;}
set{_nAb=value; }
}

#endregion
}

public interface IAbClass
{
int MyProp{get;set; }
}
}
But not this:
using System;

namespace ConsoleApplicat ion1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DerivedClass d=new DerivedClass();

d.MyProp=10;
Console.WriteLi ne(d.MyProp.ToS tring());
}
}

public class DerivedClass : BaseClass, IAbClass
{
#region IAbClass Members

public override int IAbClass.MyProp
{
get{return base.MyProp;}
set{base.MyProp =value;}
}

#endregion
}

public class BaseClass : AbClass
{
}

public abstract class AbClass : IAbClass
{
private int _nAb;
#region IAbClass Members

public virtual int IAbClass.MyProp
{
get{return _nAb;}
set{_nAb=value; }
}

#endregion
}

public interface IAbClass
{
int MyProp{get;set; }
}
}

TIA
</joel>
Nov 16 '05 #1
1 3692
The construct

class MyClass : IAbClass
{
int IAbClass.MyProp
{
...
}
}

is called an explixit interface implementation. This means that this
method is considered private unless you access the object as an
IAbClass. Therefore you cannot make it virtual nor override it.

See

http://msdn.microsoft.com/library/de...pec_13_4_1.asp

for more information.

Regards,
Joakim

Joel wrote:
Why does this work:

using System;

namespace ConsoleApplicat ion1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DerivedClass d=new DerivedClass();

d.MyProp=10;
Console.WriteLi ne(d.MyProp.ToS tring());
}
}

public class DerivedClass : BaseClass, IAbClass
{
#region IAbClass Members

public override int MyProp
{
get{return base.MyProp;}
set{base.MyProp =value;}
}

#endregion
}

public class BaseClass : AbClass
{
}

public abstract class AbClass : IAbClass
{
private int _nAb;
#region IAbClass Members

public virtual int MyProp
{
get{return _nAb;}
set{_nAb=value; }
}

#endregion
}

public interface IAbClass
{
int MyProp{get;set; }
}
}
But not this:
using System;

namespace ConsoleApplicat ion1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DerivedClass d=new DerivedClass();

d.MyProp=10;
Console.WriteLi ne(d.MyProp.ToS tring());
}
}

public class DerivedClass : BaseClass, IAbClass
{
#region IAbClass Members

public override int IAbClass.MyProp
{
get{return base.MyProp;}
set{base.MyProp =value;}
}

#endregion
}

public class BaseClass : AbClass
{
}

public abstract class AbClass : IAbClass
{
private int _nAb;
#region IAbClass Members

public virtual int IAbClass.MyProp
{
get{return _nAb;}
set{_nAb=value; }
}

#endregion
}

public interface IAbClass
{
int MyProp{get;set; }
}
}

TIA
</joel>

Nov 16 '05 #2

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

Similar topics

0
5716
by: Ian | last post by:
I've got this problem with overriding attributes on an inheritance chain where the XmlSerializer is concerned. For example: public class A { private string aWord = String.Empty(); public virtual string Word { get { return aWord; } set { aWord = value; } }
10
7343
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a Windows.Forms.UserControl in a COM environment, i.e. I want to host that control in a COM host. So far, so good, I can host it, but I can not reach the...
3
3322
by: pagates | last post by:
Hello Gurus, I have a listview, and I only want to add unique items. The problem is, my code is blowing by my "Contains" statement, adding the item, and then hitting my Compare code in the class that I have set up for my ListViewItemSorter. Here is my (simplified) code: // Note: there are accessor properties, constructors, etc // ...
12
6713
by: Rubbrecht Philippe | last post by:
Hi there, According to documentation I read the ArrayList.IndexOf method uses the Object.Equals method to loop through the items in its list and locate the first index of an item that returns True. Therefore, overriding the Equals method in the class definition of the items I put in the ArrayList should make the IndexOf method use my...
4
5945
by: Phill. W | last post by:
Here's a knotty little problem. I have some nasty little controls that needs to behave in a non- windows-Standard way - don't ask why; it's a large application being converted from some older code and my users are adamant that this behaviour mustn't change. Specifically, I want to be able to set myControl.Enabled = False
18
4715
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class...
8
1629
by: Ethan Kennerly | last post by:
Hello, There are a lot of Python mailing lists. I hope this is an appropriate one for a question on properties. I am relatively inexperienced user of Python. I came to it to prototype concepts for videogames. Having programmed in C, scripted in Unix shells, and scripted in a number of proprietary game scripting languages, I'm...
10
6920
by: Sebastian | last post by:
Hi, I'm confronted with a problem that seems not to be solvable. In general: How can I override an interface member of my base class and call the overridden method from my derived class? This is my class: class RemoteXmlDataSource : System.Web.UI.WebControls.XmlDataSource And I want to override
12
1533
by: danil52 | last post by:
Hello there, I have the following code: class Base { public: virtual void f() {cout << "Base::f()" << endl;} virtual void f(int) {cout << "Base::f(int)" << endl;} };
0
7520
marktang
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...
0
7446
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...
1
7470
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...
0
7809
tracyyun
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...
0
6041
agi2029
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...
0
3498
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...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1936
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
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.