what are namespaces in c sharp



what are namespaces in c sharp


  1. it is used to control the scope of classes in larger projects
  2. it is used to organize classes
  3. It is used to avoid code duplication in classes when there are multile vendors code
  4. c # provides us directive for shortening class which method is defined.
  5. namespace is big term defined and used when oop began to working.
  6. It is big vendor term where we can use different classes defined by different vendor names without any function

classes methods either they are same or not provided namespace keywod with relevative bundle container imported.
Namespace actually provides us the logic of wheel reinventing so it revolutioned our programming and led us to faster development.They make us avoid from collapsing against classes ,bundles, containter etc.

Namespaces are C# program elements designed to help you organize your programs. when we write a class named Console, we would need to put it in our own namespace to ensure that there wasn’t any confusion about when the System.Console class should be used or when your class should be used. Generally, it would be a bad idea to create a class named Console, but in many cases your classes will be named the same as classes in either the .NET Framework Class Library or a third party library and namespaces help you avoid the problems that identical class names would cause.

we can use and declare any one of following types in namespace in c sharp:
another namespace

Namespaces don’t correspond to file or directory names. If naming directories and files to correspond to namespaces helps you organize your code, then you may do so, but it is not required.

“The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types.”

definition by microsoft

namespace SampleNamespace
    class SampleClass { }
    interface SampleInterface { }
    struct SampleStruct { }
    enum SampleEnum { a, b }
    delegate void SampleDelegate(int i);
    namespace SampleNamespace.Nested
        class SampleClass2 { }

Example of c sharp by microsoft

c sharp tips and tricks

Leave A Reply

Your email address will not be published.