Using Namespace Aliases

11 October 2007 - 1:43 PM / by Dominic Pettifer. 1 Comment

Cool C# Snippets - Ever get tired of prefixing class names with the fully qualified namespace to avoid class name and namespace conflicts (eg. System.Namespace.AnotherNamespace.User). Well there’s a way around it using Namespace Aliases.

Type Less with Namespace Aliases

Ever grow tired of writing this...

System.Web.Namespace.AnotherNamespace.YetAnotherNamespace.User user =
	new System.Web.Namespace.AnotherNamespace.YetAnotherNamespace.User();

...all so you can use the User object in that namespace without it conflicting with about a gazillion other User classes elsewhere? If so then use a Namespace alias eg...

using MyAlias = System.Web.Namespace.AnotherNamespace.YetAnotherNamespace;

and in your code...

MyAlias.User user = new MyAlias.User();

Alternatively you can also alias the class itself eg...

using CustomUser = System.Web.Namespace.AnotherNamespace.YetAnotherNamespace.User;

and in code...

CustomUser user = new CustomUser();

Pretty cool time saving technique I reckon.

And whoa, that’s my first post on this blog in nearly 10 months! Seems I hardly get any time to write these things, so I'm going to try and write them shorter like this.

1 Comment on "Using Namespace Aliases"

Post a Comment
  • RE: Aliasing Namespaces

    Look at this, there's life on the site. And an interesting tip as well. Thx.

    Posted on 11 October 2007 - 1:29 PM / by Littlefool

    • Re:

      Some time ago, I did need to buy a good car for my business but I didn't earn enough money and couldn't buy anything. Thank goodness my mother adviced to try to take the <a href="http://bestfinance-blog.com">loans</a> from banks. Hence, I acted that and used to be satisfied with my bank loan.

      Posted on 30 May 2011 - 3:04 PM / by FULTONPansy27

    • Re:

      Previously I was wanting to know about web optimization. At this moment I know that submission supposes to be really important for my website. Hence, I determined to use the forum profiles services.

      Posted on 6 June 2011 - 7:45 AM / by forum profiles services

    • Re:

      Selecting dissertation writing and just some thesis writing service, students can’t find such kind of perfect thesis research just about this topic.

      Posted on 11 June 2011 - 12:34 AM / by custom thesis

    • Re:

      There is no matter how hard you want to compose perfect social issues essay, because the expert custom essays writing firm are able to do that better. Therefore, chill out and order free essays.

      Posted on 12 June 2011 - 6:51 AM / by history essays

    • Re:

      We utilize RSS directory submission at our rss feed submission sites. We understand that business people need RSS submissions for their sites optimization. Hence, we're right here to aid them!

      Posted on 30 September 2011 - 5:08 AM / by rss directory submission

    • Re:

      I used lots of essays writing services, nonetheless I realized that buy essay uk service was the most reliable one.

      Posted on 30 September 2011 - 1:42 PM / by essays online uk

    • Re:

      I think that to get the loan from banks you ought to present a good reason. Nevertheless, once I've got a term loan, just because I wanted to buy a car.

      Posted on 4 January 2012 - 11:48 AM / by business loans

    • Re:

      When people are not assured what to opt for, essay or just business essays paper, they would ask you, coz you know the right way to accomplish the well done article.

      Posted on 14 January 2012 - 11:13 AM / by english essays

    • Re:

      Professors claim that hard work only is needed to create good paper. Nonetheless, everything isn't very easy and common college students are not able to manage with their papers. Nevertheless, I know professional writers who should support you if you buy research paper services. Their guys aided me a lot of times.

      Posted on 14 January 2012 - 4:15 PM / by college term paper

    • Re:

      Hello, want all hear just about this good topic? In the writing work online service is not very hard to receive everything!

      Posted on 16 January 2012 - 10:28 AM / by writing work

    • Re:

      I do know that custom academic papers writing firms have good gaining and that depends on how many university students buy essay. However, such data could alter sometimes.

      Posted on 17 January 2012 - 11:07 PM / by buy essay

Leave a Comment

Comment Details
*
* BBCode: [b]bold[/b], [i]italics[/i], [code]code[/code], [li]bullet point[/li], [h]Heading[/h], [url="http://www.example.com"]link[/url], [quote author="John Smith"]quote[/quote]

Random Image

Tiny hard drive standing next to some dominoes.

These dominoes are getting bigger and bigger every year. (from the blog And So It Begins )

Quick Poll

What is your DIP/IOC Container of choice?

Poll Vote
(see results)
View Comments (625) (See previous polls)

Latest Tweets

  • And YouTube still auto-fucking-plays videos!! This is TWO-THOUSAND-AND-FUCKING-TWELVE FFS!!!

    about 20 hours ago from web
  • On a side-note, YouTube's commenting system is god-awful atrocious dreadful horrible horrible horrible!! Constant meaningless error messages

    about 20 hours ago from web
  • JavaScript is slow mmmkay http://t.co/NbB4eQjw - Actually, no, it's not http://t.co/kpGEIoPO #nodejs

    about 20 hours ago from web
  • TFS: It's super expensive, so it must be brilliant, right? Like Sharepoint #tekpubtfstitlesuggestion

    5:22 PM February 3rd from web

View Dominic Pettifer's Twitter page.