+1 vote
in C Sharp by

What is Namespace in C#? Give example of in-built Namespace in .Net?

1 Answer

0 votes
by

A Namespace is used to organize classes. Example of in-built .Net Namespace is the System Namespace.

      One can create his own Namespace and define the scope of the classes belonging to the Namespace.

      Keyword using is used in order to access a class belonging to a particular Namespace.

      A class belonging to a Namespace can be accessed only when the Namespace with the help of using directive.

      A namespace does not have any access modifiers i.e. namespace cannot be public, private, etc.

      A namespace can belong to multiple assemblies and also a single assembly can have multiple namespaces.

Example:

namespace MySpace

{

    public class A

    {

        public static void Fun()

        {

        }

    }

}namespace YourSpace{

    //Accesing the Namespace

    using MySpace;

    public class B

    {

        public void Fun()

        {

         A.Fun();

        }

    }

}

Related questions

0 votes
asked Aug 15, 2023 in React Hooks by GeorgeBell
0 votes
0 votes
asked Sep 24, 2023 in Angular by AdilsonLima
...