Home » .Net

Nested Namespace in C#

In this article, we are going to learn about Nested namespace in C#, how to implement a C# program by using nested namespaces in C#?
Submitted by IncludeHelp, on August 11, 2018

Prerequisite: Namespace in C# and The 'using' Keyword in C#

Namespaces can also be nested in C#. It means we can define namespace inside another namespace.

Syntax:

namespace <namespace_name>
{
	namespace <nested_namespace_name>
	{
		//Write code her
	}
}

We can access nested namespace using . (Dot) Operator.

Example:

using System;
using System.Collections;

using namespace1;
using namespace1.namespace2;

namespace namespace1
{
    class ABC
    {
        public void fun()
        {
            Console.WriteLine("Inside Namespace1");
        }
    }

    namespace namespace2
    {
        class XYZ
        {
            public void fun()
            {
                Console.WriteLine("Inside Namespace2");
            }
        }
    }
}
    
class Program
{
    static void Main()
    {
        ABC OB1 = new ABC();
        XYZ OB2 = new XYZ();

        OB1.fun();
        OB2.fun();

    }
}

Output

    Inside Namespace1
    Inside Namespace2





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.