CSharp - Namespace and Type Aliasing

Introduction

During the using declaration, you can give the namespace or the full qualified name an alias.

For example:

Demo

using C = System.Console;
class MainClass/*www . j  a v  a 2s . com*/
{
   public static void Main(string[] args)
   {
       C.WriteLine("book2s.com");
   }
}

Result

An entire namespace can be aliased, as follows:

Demo

using S = System;
class MainClass//from ww w . j  a va2s  . c o  m
{
   public static void Main(string[] args)
   {
       S.Console.WriteLine("book2s.com");
   }
}

Result