Set property in parent class

Set property in parent class

am 18.10.2007 22:47:37 von Fir5tSight

I have a class PrivateConnection which is a derived class from the
CoreConnection class.

class CoreConnection
{
private bool mCanWrite = true;
protected bool CanWrite
{
get { return mCanWrite; }
set { mCanWrite = value; }
}
}

class PrivateConnection : CoreConnection
{
public void ChangeParentCanWrite()
{
parent.CanWrite = false; // this will not work!
}
}

Now I want to set the "CanWrite" property in its parent object from
the method in "PrivateConnection". What's the snytax for this? Thanks!

Re: Set property in parent class

am 18.10.2007 23:39:46 von skeet

Curious wrote:
> I have a class PrivateConnection which is a derived class from the
> CoreConnection class.
>
> class CoreConnection
> {
> private bool mCanWrite = true;
> protected bool CanWrite
> {
> get { return mCanWrite; }
> set { mCanWrite = value; }
> }
> }
>
> class PrivateConnection : CoreConnection
> {
> public void ChangeParentCanWrite()
> {
> parent.CanWrite = false; // this will not work!
> }
> }
>
> Now I want to set the "CanWrite" property in its parent object from
> the method in "PrivateConnection". What's the snytax for this? Thanks!

Just

CanWrite = false;

will do. There's no "parent object" - being an instance of
PrivateConnection means you're *also* an instance of CoreConnection.

--
Jon Skeet -
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Re: Set property in parent class

am 20.10.2007 07:43:13 von MR. Arnold

"Curious" wrote in message
news:1192727670.823427.230000@y27g2000pre.googlegroups.com.. .
>I have a class PrivateConnection which is a derived class from the
> CoreConnection class.
>
> class CoreConnection
> {
> private bool mCanWrite = true;
> protected bool CanWrite
> {
> get { return mCanWrite; }
> set { mCanWrite = value; }
> }
> }
>
> class PrivateConnection : CoreConnection
> {
> public void ChangeParentCanWrite()
> {
> parent.CanWrite = false; // this will not work!
> }
> }
>
> Now I want to set the "CanWrite" property in its parent object from
> the method in "PrivateConnection". What's the snytax for this? Thanks!
>

I think you need to understand *interfaces* public or private *interfaces*.

Long

http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_int errfaces03052006095933AM/csharp_interrfaces.aspx?ArticleID=c d6a6952-530a-4250-a6d7-54717ef3b345

Short

http://preview.tinyurl.com/2emjwo