Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# namespace questions

Tags:

c#

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?

like image 286
5YrsLaterDBA Avatar asked Feb 10 '10 23:02

5YrsLaterDBA


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is C full form?

History: The name C is derived from an earlier programming language called BCPL (Basic Combined Programming Language). BCPL had another language based on it called B: the first letter in BCPL.


1 Answers

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.

like image 162
Mark Byers Avatar answered Oct 26 '22 23:10

Mark Byers