Hi Dennis,
Yes you have to have reference to an instace of the outer class.
class Outer
{
class Inner
{
private Outer mOwner;
public Inner(Outer owner)
{
mOwner = owner;
}
public void Foo()
{
mOwner.PrivateMethod(); //Can access any outer's mamber
}
}
private Inner mInner;
public Outer()
{
mInner = new Inner(this);
}
//Outer class has access to public members of mInner only
private void PrivateMethod()
{
}
}
Decalring a type nested to another doesn't inline its members into the
outer's declaration. You have to create an object of inner type.
HTH
B\rgds
100.
"Dennis C. Drumm" <de*******@primacode.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Are you refering to a nested class that has unrestricted access to the
outer class' members? I have tried that and receive a compile error "Cannot
access a nonstatic member of outer type ...". Are you sure about that? If so, how
do I access that outer class member?
Thanks,
Dennis
"100" <10*@100.com> wrote in message
news:ud**************@TK2MSFTNGP12.phx.gbl... Hi Dennis,
You can make it *intrernal* or *protected internal*. This will make the
member visible only in the assembly (internal) or assembly + derived
types (protected internal).
There is no equivalent of c++'s *friend* access modifier.
However, classes decalred inside other classes have unrestricted access
to the outer class' members regardless of their access modifiers.
HTH
B\rgds
100
"Dennis C. Drumm" <de*******@primacode.com> wrote in message
news:OP**************@TK2MSFTNGP12.phx.gbl... Is there a way with C# to allow one class access to a method or field
of another class, without making that method or field visible to all
other classes, as would be the case when making the method or field public?
Thanks,
Dennis