Thursday, 13 July 2017

Name spaces in C#

Name spaces are the container of classes & used to arrange, organize your classes in C#.They also provide help to clashing of the classes in program.
”Using” keyword are used for namespace.

Syntax:

namespace namespace_name
{
   // code declarations
}

Example.

using System;
namespace A1
{
    class Demoname
    {
        public void func()
        {
            Console.WriteLine("This is A");
        }
    }
}

namespace B1
{
    class Demoname
    {
        public void func()
        {
            Console.WriteLine("Inside second_space");
        }
    }
}

class TestClass
{
    static void Main(string[] args)
    {
        A1.Demoname fc = new A1.Demoname();
        B1.Demoname sc = new B1.Demoname();
        fc.func();
        sc.func();
        Console.ReadKey();
    }
}

Share this


0 Comments

Advertisement