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/*from  w  w w  .j  a va  2s  . c  o m*/
{
   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  v  a2  s .c om*/
{
   public static void Main(string[] args)
   {
       S.Console.WriteLine("book2s.com");
   }
}

Result