educative.io

Educative

What is Name space and how to use it?

When I learned ASP.NET project course, Educative: Interactive Courses for Software Developers.

I found the project script use name space a lot. but the namespace didn’t appear in c# path course before. I searched its definition and use case online, but don’t know how to use it. I have following questions:

  1. Where do we define name space? ex: L11, namespace People.Controllers
  2. What is the scope of name space? ex: L11, namespace People.Controllers
  3. What does the name space do, specific in this project? ex. l11, namespace People.Controllers, what does this name space do?

Hi @chao_ren

Namespaces are used in C# to organize and provide a level of separation of codes. They can be considered as a container that consists of other namespaces, classes, etc. Following are answers to your numbered questions:

  1. Please go through the files Startup.cs and Program.cs where main() function and other definitions are present. You will see the declaration there. Namespace name is “People” but as we working in the MVC model so it is People.Controller and People.Model respectively.
  2. Scope of this namespace is for this whole project.
  3. Namespaces* are used to organize and provide a level of separation of codes. They can be considered as a container that consists of other namespaces, classes and they are doing the same for this project too.