Is it possible to declare a class in C# that is only valid to be used within its namespace?
Example:
namespace a
{
public class Dog
{
public void sayHello()
{
System.Console.WriteLine('hello');
}
}
}
namespace b
{
public class DogWalker
{
public void Walk()
{
Dog dog = new Dog();
dog.sayHello();
}
}
}
namespace a
{
public class DogWalker
{
public void Walk()
{
Dog dog = new Dog();
dog.sayHello();
}
}
}
In the case above the DogWalker in Namespace b should throw an error message on compile, but DogWalker in namespace a should be allowed since its in the same namespace as the Dog.
If anyone can point me the right direction, it would be much appreciated.
You can achieve this by separating the classes into different assemblies and declaring them as
internal.