The namespace ALIAS is the concept of giving shorthand names to the bigger namespace.
->Generally only use namespace aliases when using two classes with the same name.
->It will improve the code readability and understandability.
Note:
Namespace aliasing concept will be useful for resolving the naming conflict by giving short hand name along with the class names instated of full namespace.
->Generally only use namespace aliases when using two classes with the same name.
->It will improve the code readability and understandability.
Note:
Namespace aliasing concept will be useful for resolving the naming conflict by giving short hand name along with the class names instated of full namespace.
Sample code:
namespace SampleNamespace
{
class SampleClass
{
public void SampleMethod()
{
System.Console.WriteLine(
"SampleMethod inside SampleNamespace");
}
}
// Create a nested namespace, and define another class.
namespace NestedNamespace
{
class SampleClass
{
public void SampleMethod()
{
System.Console.WriteLine(
"SampleMethod inside NestedNamespace");
}
}
}
class Program
{
static void Main(string[] args)
{
// Displays "SampleMethod inside SampleNamespace."
SampleClass outer = new SampleClass();
outer.SampleMethod();
// Displays "SampleMethod inside SampleNamespace."
SampleNamespace.SampleClass outer2 = new SampleNamespace.SampleClass();
outer2.SampleMethod();
// Displays "SampleMethod inside NestedNamespace."
NestedNamespace.SampleClass inner = new NestedNamespace.SampleClass();
inner.SampleMethod();
}
}
}
No comments:
Post a Comment