A namespace are used to organised your programme. they provide assistance in avoiding name classes.
Defining a Namespace
namespace namespace_name
{
// code
}
To call the namespace-enabled version of either function or variable the namespace name as follows:
namespace_name.item_name;
The following program demonstrates use of namespaces:
using System; using xyz namespace First { using M; class Program { static void Main() { // Can access CClass type directly from xyz zClass class1 = new CClass(); // Can access DClass type from M. MClass class2 = new DClass(); // Must explicitely specify F namespace. F.FClass class3 = new F.FClass(); // Display types. Console.WriteLine(class1); Console.WriteLine(class2); Console.WriteLine(class3); } } } namespace x { namespace y { namespace z { public class zClass { } } } } namespace M { public class MClass { } } namespace F { public class FClass { } }
OUTPUT :-
XYZ.ZClass
M.MClass
F.FClass
Previous.......
Next......
No comments:
Post a Comment