Does declaring a nested class has some functional/hierarchical impact on the objects or is just a matter of access/visibility.
I have 4 classes on my program but I only want to make 1 of them public, originally I declared them as follows:
namespace mynamespace{
private class A{
// some members;
}
private class B{
// some members;
}
private class C{
// some members;
}
public class D{
// some members;
}
}
but the compiler complained, so among other things, I changed private to internal, however opposite to what I thought, all 4 classes are available to external programs, which I don't want. I tried everything I could imagine but no luck, so I thought I should try nesting class A, B and C inside class D, as follows:
namespace mynamespace{
public class D{
// some members;
private class A{
// some members;
}
private class B{
// some members;
}
private class C{
// some members;
}
}
}
...this way only the class I want to publish is actually published, however since I'm new to C# I'm not sure this is the proper way to do it. I worry this change could have consequences related to memory consumption, performance, etc.
internal
member is only visible within the same assembly.A
,B
, orC
from withinD
.