Reputation: 35
I apologize if there's an answer out there, but I couldn't find any.
I'm currently in the situation shown as below. I expected it to throw an error, but it didn't.
The variable inside 'Outer' called 'inner', is an instance of Outer.Inner, the private nested class. I'm wondering how it's possible to access the non-nested Inner instance.
This probably could be done by using different namespaces, but is there any other way?
public class Outer {
private Inner inner = new Inner(); // This is the Outer.Inner class
private class Inner { }
}
public class Inner { }
Upvotes: 0
Views: 645
Reputation: 13684
If you don't want to wrap it in namespaces you can use global::
to refer to types inside the global namespace:
public class Outer
{
private global::Inner inner = new global::Inner();
private class Inner
{
}
}
public class Inner
{
}
Upvotes: 2
Reputation: 501
This seems to work fine.
I used the namespace before the class name.
namespace Example
{
public class Outer
{
private Example.Inner inner = new Example.Inner();
private class Inner { }
}
public class Inner { }
}
Upvotes: 1