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.
Related C# job interview questions
What is a class in C#?
C# JuniorWhat are the advantages of using 'using' keyword in C# and why would you use it?
C# JuniorWhat is abstract class and what is it good for?
C# MediorWhat is covariance and contravariance?
.NETASP.NET MVCASP.NET WebAPIASP.NET WebFormsC# SeniorHave you ever consumed some 3rd party API? What was it? Have you ever designed your own API? Could you describe it a bit?
.NETArchitectureASP.NET WebAPIC#Web services Medior