C# Using alias directives

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>;
}

Enjoy !

This entry was posted in Code. Bookmark the permalink.

2 Responses to C# Using alias directives

  1. Jan Wikholm says:

    Yeah.

    We’ve been using this in our CMS system because we have our own “File” and incidentally it uses System.IO.File too so we need to specify that using File = ournamespace.File; and then just use the fully-qualified name for IO Files.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>