What is a namespace in C# and what is it good for?

Experience Level: Junior
Tags: C#

Answer

  • A namespace is like a box that you can use for storing your classes.
  • It is used for organizing code.
  • A namespace can contain zero, one or more classes.
  • A namespace is created using namespace keyword.
  • A namespace name consists of one string or multiple strings delimited by dot character.
  • It is a best practice to start each word of the namespace name by a capital letter.
  • One namespace can be used in multiple .cs files.
  • There can be multiple namespaces in one .cs file.
Example
namespace Furniture.Tables {

}

namespace Furniture.Chairs {

}
Related C# job interview questions
C# for beginners
C# for beginners

Are you learning C#? Try our test we designed to help you progress faster.

Test yourself