Is there a access modifier (like public, private, etc) that makes all classes in the same namespace (in the same folder) friends?
Example:
namespace MYPROJ.As {
public class A {
_______ A() {....}
}
}
namespace MYPROJ.As {
public class B {
public DoSomething() {
new A(); //I WANT THIS TO WORK
}
}
}
namespace MYPROJ.Cs {
public class C {
public DoSomething() {
new A(); //I DON'T WANT THIS TO WORK
}
}
}
EDIT
I want only B to be able instanciate A. How cam I do that?
If by “folder” you really mean “namespace” – no. None of the .NET access modifiers are related to namespaces at all.
Basically what controls accessibility is:
InternalsVisibleTo(internal access)There’s also
protected internal, but I can never remember which way round that works, and I almost never use it 🙂So if you can put class C into a different assembly to A and B (which are in the same assembly as each other), then you can make the constructor to A
internaland get the result you want.