To define a namespace in C #, we use the keyword's namespace followed by a namespace and curly brackets that contain the namespace name, as follows:
namespace name
{
//classes
//methods
//etc
}
Members are accessed by using the operator (.). The class in C # is known for its respective namespace.
using System;
namespace Entrypoint
{
class Tech
{
public static void show()
{
Console.WriteLine("Shahzad Hussain");
}
}
}
class Tech1
{
public static void Main(String[] args)
{
Entrypoint.Tech.show();
}
}
Shahzad Hussain
You can also specify a namespace in another namespace, which is called nested namespaces. To use members of a built-in namespace, the user must use the period (.) Operator.
using System;
namespace Entrypoint
{
namespace NestedNamespace
{
class Tech
{
public Tech()
{
Console.WriteLine("Nested Namespace");
}
}
}
}
class Tech1
{
public static void Main(String[] args)
{
new Entrypoint.nestednamespace.Tech();
}
}
Nested Namespace
In fact, it is impractical to call a function or class (or you can say members of their space) every time you use their full name. The example above is System.Console.WriteLine (“Shahzad Hussain”); a Entrypoint.Tech();
full name. Thus, C # provides a "using" keyword that helps the user not to re-enter their full names. The user only needs to specify the space name at the beginning of the program, then he can easily avoid using full names.
using System;
using Entrypoint;
namespace Entrypoint
{
class Tech
{
public static void show()
{
Console.WriteLine("Shahzad Hussain");
}
}
}
class Tech1
{
public static void Main(String[] args)
{
Tech.show();
}
}
Shahzad Hussain