#524 – All Types Within a Namespace Must Be Unique

You can create more than one type with the same name, as long as the exist in different namespaces.  But within a particular namespace, the name of every type must be unique.

In the example below, we declare a Dog class in both the EarthDogs and AlienDogs namespaces.

namespace EarthDogs
{
    public class Dog
    {
        public string Name { get; set; }

        public void Bark()
        {
            Console.WriteLine("Woooof");
        }
    }
}

namespace AlienDogs
{
    public class Dog
    {
        public string Name { get; set; }

        public void Bark()
        {
            Console.WriteLine("Snarkzuggrootzen");
        }
    }
}

(In practice, for these classes, you’d probably instead declare a Dog parent class and subclasses EarthDog and AlienDog, which would override the Bark method).