473,659 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set property in parent class

I have a class PrivateConnecti on 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 PrivateConnecti on : CoreConnection
{
public void ChangeParentCan Write()
{
parent.CanWrite = false; // this will not work!
}
}

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

Oct 18 '07 #1
2 1438
Curious <fi********@yah oo.comwrote:
I have a class PrivateConnecti on 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 PrivateConnecti on : CoreConnection
{
public void ChangeParentCan Write()
{
parent.CanWrite = false; // this will not work!
}
}

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

CanWrite = false;

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

--
Jon Skeet - <sk***@pobox.co m>
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********@yah oo.comwrote in message
news:11******** **************@ y27g2000pre.goo glegroups.com.. .
>I have a class PrivateConnecti on 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 PrivateConnecti on : CoreConnection
{
public void ChangeParentCan Write()
{
parent.CanWrite = false; // this will not work!
}
}

Now I want to set the "CanWrite" property in its parent object from
the method in "PrivateConnect ion". 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
2074
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 overflow. All I know is that the program is either stopped due to an exception at the end of Main or has exited after the Stack Overflow exception. (Both cases are Debug builds running in the debugger.) After a lot of trial and error (mostly...
3
1331
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 set_Text(String *s) { Parent::Text = s; } };
4
3239
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. One problem I'm having is that I don't know the type of the parent webform until run-time. Is this possible? And if so, how can I do this? Thank you, Ben
6
9056
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
1742
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 I try to access the properties in the page_init of the parent class, I get an "Object reference not set to instance of object" error. I understand the load sequence of a page, but need help initalizing the abstract class in the page_init so I...
2
1141
by: shapper | last post by:
Hello, I have two classes defined as follows: Public Class Parent ... Public Class Child ... End Class End Class
11
3958
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 is instance of MyEntity class. There is no MyProperty property in MyObject at design time.
61
2949
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; function my_baseclass(){ $this->TableName = "";
18
1637
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 implemented this in my current bit of work. It works well enough, but I can't help feeling there a cleaner more
10
10023
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
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8525
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7356
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2750
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
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.