473,714 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to access nested parent?

Hello

//-----------------
I have following situation:
public class Class1
{
public struct Struct1
{
public void Function1()
{
//Question here. How to access current Class1 instance
}
}
}
//-----------------

Struct1 is nested into Class1.
My Question is how to access from Struct1 code, to current Class1 instance.

Thank you.

Mar 12 '06 #1
6 1668
Hi MilanB,
to access an instance of Class1 from Struct1 you need to pass in the
instance of Class1 as a reference either in the constructor or in whatever
method you are calling.

Mark Dawson
http://www.markdawson.org
"MilanB" wrote:
Hello

//-----------------
I have following situation:
public class Class1
{
public struct Struct1
{
public void Function1()
{
//Question here. How to access current Class1 instance
}
}
}
//-----------------

Struct1 is nested into Class1.
My Question is how to access from Struct1 code, to current Class1 instance.

Thank you.

Mar 12 '06 #2
Hello Mark,

Thank you for suggestion.

MilanB.
Mar 12 '06 #3
"MilanB" <Mi****@discuss ions.microsoft. com> wrote in message
news:31******** *************** ***********@mic rosoft.com...
Hello

//-----------------
I have following situation:
public class Class1
{
public struct Struct1
{
public void Function1()
{
//Question here. How to access current Class1 instance
}
}
}
//-----------------

Struct1 is nested into Class1.
My Question is how to access from Struct1 code, to current Class1 instance.


Hi,
Mark already gave you the solution, but I have a few comments.
In your example, there is NO instance of Class1 associated with an instance of Struct1.
You can create a new Struct1 without ever creating a Class1 (and vice versa)
Nested classes have a scoping relationship with each other.
This does not imply that an instance of Outer contains an instance of Outer.Inner
Here is a simple test program (I changed Struct1 to a class and changed the names)
-----------------------
using System;

public class Test
{
static void Main()
{
Outer.Inner inner = new Outer.Inner();
inner.FUNC();
}
}

public class Outer
{
public Outer()
{
Console.WriteLi ne("new Outer()");
}
public class Inner
{
public Inner()
{
Console.WriteLi ne("new Outer.Inner()") ;
}
public void FUNC()
{
Console.WriteLi ne("In FUNC()");
}
}
}
-----------------------
Output:
new Outer.Inner()
In FUNC()

We created an instance of Outer.Inner without ever creating an instance of Outer

Hope this helps
Bill



Mar 12 '06 #4
Thanks Bill!
Mar 12 '06 #5
"Bill Butler" <qw****@asdf.co m> wrote in message
news:4kYQf.2637 $hc.2193@trndny 03...
Nested classes have a scoping relationship with each other.
This does not imply that an instance of Outer contains an instance of
Outer.Inner


Exactly. All objects are peers and exist as areas of memory on the heap or
the stack. Some objects hold references to other objects, but no object is
ever physically contained within another. Objects generally don't know which
other objects hold references to them, unless they have been told (e.g. a
reference passed in via a constructor). This is true even for objects that
are defined as private within other objects.
Mar 12 '06 #6
Thanks Rick
Mar 13 '06 #7

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

Similar topics

2
9710
by: Heiko Henkelmann | last post by:
Please see the following example. Is there any other way to access SomeAttribute from the nested class, without having to use the actual name of the outer class? class SomeClass: SomeAttribute = 1 class SomeNestedClass: SomeOtherAttribute = 2
10
4548
by: Paul Morrow | last post by:
I'm hoping that someone can explain why I get the following exception. When I execute the code... ###################################### class Parent(object): class Foo(object): baz = 'hello from Parent.Foo' class Child(Parent): #Foo.baz = 'hello from Child.Foo'
12
3977
by: Jeff Lanfield | last post by:
First of all, I apologize if coalescing is not the right term to describe my problem. I have a tree where each node has the same set of attributes (is the same entity) but child nodes should inherit attribute values from parent node. for example, say I have the following table: (nodeId int , color varchar, phone varchar) with two rows 5, "GREEN", "555-1212"
8
16910
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. This works fine if all of the properties are at the top (root level) of the model but I'd like to keep them in nested classes to organize them better. So, for example, part of my data model looks like this (simplified) : public class MainClass
9
7610
by: John Sidney-Woollett | last post by:
Is it possible to use the dblink and dblink_exec features from inside pl/pgsql functions to mimic the behaviour of nested transactions by calling another function or executing some SQL via the dblink (into the same database)? Does the SQL statement executed within the dblink sit in its own isolated transaction/session? And would an error thrown in the dblink statement abort the enclosing session that initiated the call? What is the...
6
3110
by: Marc Hoeijmans | last post by:
How is it possible to us a property from a nested class. Example: namespace MyApp { public class MaxLength { public class Project {
3
6050
by: Steve Teeples | last post by:
Can someone tell me how to access the "nested child" data of a specific parent from within a dataset? I read an XML file into a dataset with its schema and want to access the child nested data. The one I access is identified by a unique value within the parent data. In the below snippet, I'll loop through the LanguageData64 entries and find the Code (e.g., 00). From there are want to access the PartNumbers and return a reference to that...
5
2981
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML document into a text document with a single row for each parent node (that has all of the values from all of the child nodes for that row) The DataView within VS 2005 IDE displays my 15 or so child tables - and knows that some parent rows...
1
6837
by: mohaaron | last post by:
Can anyone tell me how to get a nested UpdatePanel to update when the trigger control is in the parent UpdatePanel and I don't want to parent to update? I'm trying to change the Visible property of a control in the nested UpdatePanel using a control in the parent UpdatePanel and it's always refeshing the parent as well.
2
2826
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
0
8704
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9071
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
9009
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7946
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
6627
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
4462
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...
0
4715
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.