I have this piece of code, and error is generated, just because I haved added into a constructor for its class.
class NestedClass
{
class A
{
A() {}
}
class B
{
// no constructor
}
public static void run()
{
A a = new A(); // error
B b = new B(); // no error
}
}
And error is:
NestedExample.A is inaccessible due to protection level
Please help me explain this.
Thanks 🙂
Define your constructor as public
Your constructor for class
Ais privatePrivate Constructors (C# Programming Guide) – MSDN
The reason it is working for B is that you haven’t specified any constructor and for default constructor:
Constructor – MSDN