Search This Blog

2009-12-01

Tutorial 5:Namespaces

Namespaces are C# program elements designed to help you organize your programs. They also provide assistance in avoiding name clashes between two sets of code. Implementing Namespaces in your own code is a good habit because it is likely to save you from problems later when you want to reuse some of your code. // Namespace Declarationusing System;

// The Portal-management Namespacenamespace Portal-management { // Program start class class NamespaceCSS { // Main begins program execution. public static void Main() { // Write to console Console.WriteLine("This is the new Portal-management Namespace."); } }} It shows how to create a namespace. We declare the new namespace by putting the word namespace in front of Portal-management. Curly braces surround the members inside the Portal-management namespace.

In summary, you know what a namespace is and you can declare your own namespaces. If you don't want to type a fully qualified name, you know how to implement the using directive. When you want to shorten a long namespace declaration, you can use the alias directive. Also, you have been introduced to some of the other namespace members in addition to the class type.