#522 – The Fully Qualified Name for a Type Includes the Namespace
February 17, 2012 1 Comment
If we define a Dog type in the DogLibrary namespace, the fully qualified name for the new type is DogLibrary.Dog. You can use this full name when working with the type.
DogLibrary.Dog kirby = new DogLibrary.Dog(); kirby.Bark();
If you’re writing code that exists in the same namespace as a type, you can omit the namespace and just use the short version of the type name.
namespace DogLibrary { public class Dog { public string Name { get; set; } public int Age { get; set; } public void Bark() { Console.WriteLine("WOOOOOF!"); } } public static class DogFactory { public static Dog MakeDog(string name, int age) { // Can just use "Dog" as type name Dog d = new Dog(); d.Name = name; d.Age = age; return d; } } }