Set property in parent class

  • Thread starter Thread starter Curious
  • Start date Start date
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!
 
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.
 
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
 
Back
Top