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

Result