I want a method of the class: ‘One‘ (‘AccessibleWithinSameNamespace‘) to be accessible by the class: ‘Two‘, without having ‘Two‘ extending ‘One‘.
Both classes are in the same namespace, so I’m thinking that maybe there’s an access-modifier that emulates the ‘protected‘ modifyer, but for namespaces.
Some code:
namespace Test { class One { public void AccessibleToAll() { } protected void AccessibleWithinSameNamespace() { // I am not public // I can be accessed from other classes // within the same namespace of my class } } } namespace Test { class Two { public Two() { One one = new One(); // I am able to access this method because my class // is in the same namespace as the class: 'One' one.AccessibleWithinSameNamespace(); } } }
You can use the internal modifier if both classes are in the same assembly.
With your example: