Javatpoint Logo
Javatpoint Logo

C# Namespaces

Namespaces in C# are used to organize too many classes so that it can be easy to handle the application.

In a simple C# program, we use System.Console where System is the namespace and Console is the class. To access the class of a namespace, we need to use namespacename.classname. We can use using keyword so that we don't have to use complete name all the time.

In C#, global namespace is the root namespace. The global::System will always refer to the namespace "System" of .Net Framework.

C# namespace example

Let's see a simple example of namespace which contains one class "Program".

Output:

Hello Namespace!

C# namespace example: by fully qualified name

Let's see another example of namespace in C# where one namespace program accesses another namespace program.

Output:

Hello First Namespace
Hello Second Namespace

C# namespace example: by using keyword

Let's see another example of namespace where we are using "using" keyword so that we don't have to use complete name for accessing a namespace program.

Output:

Hello Namespace
Welcome Namespace




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA