views:

95

answers:

2

If you have a namespace that contains a property in ClassA and a class that has the name of that Property somewhere else in your project and both are in the same namespace this won't cause conflicts will it?

So lets say I have a class named Car

namespace Dealer
{
   class Vehicle
   {
        // the main class that defines vehicle, so this is Dealer.Vehicle  (Vehicle.cs)
   }
}

and a property over in some other class

namespace Dealer
{
    class Dealer
    {
        public Vehicle Vehicle
        {
           get { return _vehicle; }
        }
    }
}

so for the second it is really this for the property

public Dealer.Vehicle Vehicle
{
     get { return _car; }
}

so now you have Dealer.Vehicle and Dealer.Dealer.Vehicle. Wondering of that would cause a conflict ever.

If both those classes are in the same namespace and

+3  A: 
namespace Dealer
{
    class Dealer
    {
        ...
    }
}

Wondering if that would cause a conflict ever.

Yes, that will cause problems. Do not name a class the same as its namespace. Eric Lippert has written a series of articles about this.

Mark Byers
+1 I was about to write the same, and reference the same location.
Will Marcouiller
I wasn't the one who did that..just wondering. I would never name a class as same as its namespace...it's stupid. But this is legacy code.
CoffeeAddict
A: 

First off, do not name the class the same as its namespace.

Second, having a property of the same name as its class will work fine, as I have done it often.

Will Marcouiller