Set property in parent class

C

Curious

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!
 
J

Jon Skeet [C# MVP]

Curious said:
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.
 
M

Mr. Arnold

Curious said:
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/Upload...rticleID=cd6a6952-530a-4250-a6d7-54717ef3b345

Short

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top