John Lam 1997 — 2026

Cool C# feature spotted

I didn’t know about namespace aliasing before I spotted it in some sample code this morning:

using Channels = System.Runtime.Remoting.Channels;

This is really nice if you have namespace conflicts and need to disambiguate your type references, or if you’re from the school of thought that says that you must always use fully qualified type names, but don’t want to obscure your code with giant namespace references.

8 archived reader comments

Tomas Restrepo (2003-02-02)

This is indeed a nice feature. Unfortunately, I’ve always thought C# namespace name resolution was only half done… For example, if you have a class X in namespace M.N, there’s no way to say: using M; … N::X x = N::X. This sucks, in my opinion, cause you either use a full namespace name, a complete namespace using declaration, or an alias.

Brian Randell (2003-02-02)

What’s funny is that you can do using on a class in Visual Basic .NET using the VB’s Imports command. For example, I usually do: Imports System.Runtime.InteropServices.Marshal so that I can then just use ReleaseComObject(obj) Brian

Mark Hurley (2003-02-02)

I couldn’t agree with you any more Thomas. I hope in v2 that the MS folks change their implementation.

Jesse Ezell (2003-02-02)

I agree as well…isn’t it possible to use partial specifications if you are inside the namespace though? For instance if you have a class M.N.X: namespace M { public class Y { public DoSomething() { N.X x = new N.X(); } } } I get autocomplete in VS.NET on that type of thing, so it has always confused me why one gives it and not the other. Never took the time to look at it in depth though. –Jesse

adam (2003-02-02)

Don’t forget you can alias class names as well. using mb = System.Windows.Forms.MessageBox; mb.Show(“”);

Rick Childress (2003-02-04)

“Don’t forget you can alias class names as well.” As a developer, I would _never_ want to see that. You’re in for some serious heartache when people start doing that.

adam (2003-02-04)

nor would i, however just imagine the impossible to read code you can write

Brad More (2003-02-04)

I think we are! RUN AWAY SCREAMING … AAaaauuuuugggghhh