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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| 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 EarthDogand AlienDog, which would override the Bark method).