Click here to Skip to main content
15,121,851 members
Articles / Programming Languages / C#
Alternative
Tip/Trick
Posted 6 Sep 2011

Tagged as

Stats

5.8K views
1 bookmarked

Type aliasing in using declarations

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
2 Oct 2011CPOL
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)

Share

About the Author

Reiss
Program Manager
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
GeneralIs there any way to define an alias on "assembly" level to p... Pin
Ivan Yakimov2-Oct-11 23:44
professionalIvan Yakimov2-Oct-11 23:44 
GeneralThankyou for your feedback. Yes, i Agree, in most cases you... Pin
GParkings5-Sep-11 23:15
MemberGParkings5-Sep-11 23: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.