"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