Jan 20, 2020 in C Sharp
Q:

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

1 Answer

0 votes
Jan 20, 2020

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
Oct 18, 2019 in C Sharp
  • sealed-class-c#
  • c#-sealed-class
0 votes
Mar 4 in LISP
0 votes
+1 vote
Jun 25, 2019 in Dot Net
...