0
What's namespace and what's it's use and why main function is declared inside namespace........
2 Réponses
0
A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace does not conflict with the same class names declared in another.
for ex:- namespace definition or declaration
namespace namespace_name
{
// code declarations
}
complete program code:-
using System;
namespace first_space
{
class namespace_cl
{
public void func()
{
Console.WriteLine("Inside first_space");
}
}
}
namespace second_space
{
class namespace_cl
{
public void func()
{
Console.WriteLine("Inside second_space");
}
}
}
class TestClass
{
static void Main(string[] args)
{
first_space.namespace_cl fc = new first_space.namespace_cl();
second_space.namespace_cl sc = new second_space.namespace_cl();
fc.func();
sc.func();
Console.ReadKey();
}
}
explanation - here in this program both namespace has same name class but it does not effect the yield output.
0
output :-
Inside first_space
Inside second_space