C# Using alias directives

March 25th, 2009 by Julien Palard

Just found in section 9.4.1 of the C# language specification :
The using keyword can be used to alias a namespace or a type name :

using-alias-directive:
using identifier = namespace-or-type-name ;


You can read more about that here : csharp language specification.doc

Or just try to use it :

// As the specification show it :
namespace N1.N2
{
                class A {}
}
namespace N3
{
                using A = N1.N2.A;
                class B: A {}
}

// My foobar exemple :
namespace Foo
{
                using Bar = Dictionary<string, string>;
}

Download this code: ex.cs

Enjoy !

One Response to “C# Using alias directives”

  1. Eber Irigoyen Says:

    yup, I’ve used this technique to hide generics complexity

    http://ebersys.blogspot.com/2006/08/hiding-generics-complexity.html

Leave a Reply

You must be logged in to post a comment.