Click here to Skip to main content
15,886,004 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Type aliasing in using declarations

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
2 Oct 2011CPOL 6.8K   1   2
Whilst this is a good tip, I wouldn't go as far as qualifing an entire class as you have done. I would stop at the namespace level, so your example becomes:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using Media =...
Whilst this is a good tip, I wouldn't go as far as qualifing an entire class as you have done. I would stop at the namespace level, so your example becomes:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Media = System.Windows.Media;
 
namespace WindowsFormsApplication1
{
    class With
    {
        public void Foo()
        {
            Color winformsColor = Color.AntiqueWhite;
            Media.Colour wpfColor = new Media.Colour();
 
            Console.WriteLine(winformsColor.ToString() + wpfColor.ToString());
        }
    }
}


I think this is more readable and less likely to confuse others who may go looking for a class definition that doesn't exist.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Program Manager
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralIs there any way to define an alias on "assembly" level to p... Pin
Ivan Yakimov2-Oct-11 22:44
professionalIvan Yakimov2-Oct-11 22:44 
GeneralThankyou for your feedback. Yes, i Agree, in most cases you... Pin
GParkings5-Sep-11 22:15
GParkings5-Sep-11 22:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.