65.9K
CodeProject is changing. Read more.
Home

Type aliasing in using declarations

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Sep 6, 2011

CPOL
viewsIcon

7502

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:
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.