C# NAMESPACES
Namespace is a set of retaining the name provides a way to separate the other is designed for. The name of the class that is declared in a namespace declared in the same class name does not conflict with another.Define a Namespace
Namespace definition keywords namespace namespace name is followed by the following:
Call it this version is activated by the function or variable namespace, add the name of the namespace as follows:
The following program demonstrates use of namespaces:
When the above code is compiled and executed, it produces the following result:
The Use of Keywords
The use of keywords indicate that this program uses names in a particular namespace. For example, we use the System namespace in our program. There is a defined class of console. We simply write:
We could have written the fully qualified name as:
You can also avoid placing namespaces with the using namespace directive. This directive tells the compiler that the next code makes use of the name in a particular namespace. Namespace then implied for the following code:
Let's rewrite our previous example, using the instructions:
When the above code is compiled and executed, it produces the following result:
Nested Namespaces
You can define one namespace inside another namespace as follows:
You can access members of nested namespace by using the dot (.) operator as follows:
When the above code is compiled and executed, it produces the following result:
No comments:
Post a Comment