Monday, April 30, 2012

Why Namespaces


Namespaces are used in .Net to organize class libraries into a hierarchical structure and
reduce conflicts between various identifiers in a program. By helping organize classes,
namespaces help programmers manage their projects efficiently and in a meaningful way
that is understood by consumers of the class library. Namespaces enables reusable
components from different companies to be used in the same program without the worry
of ambiguity caused by multiple instances of the same identifier.
Namespaces provide a logical organization for programs to exist. Starting with a toplevel
namespace, sub-namespaces are created to further categorize code, based upon its
purpose.
In .Net, the base class library begins at the System namespace. There are several classes
at the System level such as Console, Exception etc. The namespace name gives a good
idea of the types of classes that are contained within the namespace. The fully qualified
name of a class is the class name prefixed with the namespace name. There are also
several nested namespaces within the System namespace such as System.Security,
System.IO, System.Data, System.Collections etc.
Reducing conflict is the greatest strength of namespaces. Class and method names often
collide when using multiple libraries. This risk increases as programs get larger and
include more third-party tools.

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...