In C#, a namespace is a collection of related types. The fully qualified name of every type actually includes the namespace that it’s defined in.
You use the namespace keyword to define a namespace. All types defined within the pair of braces that follow the namespace name then belong to that namespace.
In the example below, the Dog class belongs to the DogLibrary namespace.
1
2
3
4
5
6
7
8
9
10
11
12
13
| namespace DogLibrary { public class Dog { public string Name { get ; set ; } public int Age { get ; set ; } public void Bark() { Console.WriteLine( "WOOOOOF!" ); } } } |
Because Dog is defined within the DogLibrary namespace, the fully qualifed name of the Dog type isDogLibrary.Dog.