473,506 Members | 16,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set property in parent class

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!

Oct 18 '07 #1
2 1435
Curious <fi********@yahoo.comwrote:
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 18 '07 #2

"Curious" <fi********@yahoo.comwrote in message
news:11**********************@y27g2000pre.googlegr oups.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/UploadF...7-54717ef3b345

Short

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

Oct 20 '07 #3

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

Similar topics

13
2055
by: Will Pittenger | last post by:
I have a Control derived class. When the parent of the control changes the control's Location property, the stack overflows. I have not found a way to find out what was on the stack when it does...
3
1319
by: Huihong | last post by:
I found when invoking the same property of a base class, the MC++ compiler seems to emit incorrect IL code, and causes causes stack overflow: class Child : public Parent { __property void...
4
3232
by: Ben Amada | last post by:
Hello, I have a user control which will be dynamically loaded from one of two parent ASPX webforms. Within the user control I'd like to be able to access a property from the parent webform. ...
6
9037
by: Cc | last post by:
hi, is there a way to use byref on property set , because i would like to pass the value into the variable byref ?
1
1733
by: =?Utf-8?B?R2FsYWhhZA==?= | last post by:
I have an ascx file that inherits an abstract class. Within this abstract class are protected properties. I can access these properties within the page_load event of the parent class, however when...
2
1132
by: shapper | last post by:
Hello, I have two classes defined as follows: Public Class Parent ... Public Class Child ... End Class End Class
11
3944
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
61
2903
by: Sanders Kaufman | last post by:
I'm wondering if I'm doing this right, as far as using another class object as a PHP class property. class my_baseclass { var $Database; var $ErrorMessage; var $TableName; var $RecordSet;...
18
1628
by: David Moss | last post by:
Hi, I want to manage and control access to several important attributes in a class and override the behaviour of some of them in various subclasses. Below is a stripped version of how I've...
10
9988
by: Derek Hart | last post by:
I can set focus to my property grid by using propgrid.Focus - but how can I set the default property that is always first? Or just set focus to the default property? Can this be done?
0
7218
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,...
0
7103
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...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
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...
0
7478
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...
0
5614
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,...
0
4701
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...
0
3188
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...
0
1532
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 ...

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.