473,471 Members | 1,684 Online
Bytes | Software Development & Data Engineering Community
Create 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 1649
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****@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.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.WriteLine("new Outer()");
}
public class Inner
{
public Inner()
{
Console.WriteLine("new Outer.Inner()");
}
public void FUNC()
{
Console.WriteLine("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.com> wrote in message
news:4kYQf.2637$hc.2193@trndny03...
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
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:...
10
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...
12
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...
8
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. ...
9
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...
6
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
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. ...
5
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...
1
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...
2
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
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.