5YrsLaterDBA
5YrsLaterDBA

Reputation: 34730

C# namespace questions

what's the difference for the following two ways to define namespace?

namespace A.B.C {
     public class AA{

    }
}

namespace A {
    namespace B{
        namesapce C{
            public class AA{

            }
        }
    }
}

in some where I may have

namespace A{
//some classes 
}

namespace A.B {
//some classes
}

namespace A {
namespace B {
 //some classes
}
}

Both need to do the same to use class AA by using A.B.C; Can I use C.AA a; to specify the AA class in C namespace or I have to use the fall namespace convention: A.B.C.AA a; to avoid possbile confliction?

Upvotes: 9

Views: 297

Answers (1)

Mark Byers
Mark Byers

Reputation: 837926

They're the same. If you look at this code in .NET Reflector:

namespace A {
namespace B{
namespace C{
public class AA{

}
}
}
}

you get this:

namespace A.B.C
{
    public class AA
    {
        // Methods
        public AA();
    }
}

Both methods are compiled to exactly the same intermediate language code.

Upvotes: 9

Related Questions