Namespaces are the way that .NET avoids name clashes between classes. They are designed to prevent
situations in which you define a class to represent a customer, name your class Customer , and then someone else does the same thing (a likely scenario — the proportion of businesses that have customers seems to be quite high).
A namespace is no more than a grouping of data types, but it has the effect that the names of all data
types within a namespace are automatically prefixed with the name of the namespace. It is also possible
to nest namespaces within each other. For example, most of the general - purpose .NET base classes are in a namespace called System . The base class Array is in this namespace, so its full name is System.Array.
.NET requires all types to be defined in a namespace; for example, you could place your Customer class
in a namespace called YourCompanyName . This class would have the full name:
YourCompanyName.Customer
If a namespace is not explicitly supplied, the type will be added to a nameless global namespace.
Microsoft recommends that for most purposes you supply at least two nested namespace names: the first
one represents the name of your company, and the second one represents the name of the technology or
software package of which the class is a member, such as YourCompanyName.SalesServices.Customer.
This protects, in most situations, the classes in your application from possible name clashes with classes
written by other organizations.
situations in which you define a class to represent a customer, name your class Customer , and then someone else does the same thing (a likely scenario — the proportion of businesses that have customers seems to be quite high).
A namespace is no more than a grouping of data types, but it has the effect that the names of all data
types within a namespace are automatically prefixed with the name of the namespace. It is also possible
to nest namespaces within each other. For example, most of the general - purpose .NET base classes are in a namespace called System . The base class Array is in this namespace, so its full name is System.Array.
.NET requires all types to be defined in a namespace; for example, you could place your Customer class
in a namespace called YourCompanyName . This class would have the full name:
YourCompanyName.Customer
If a namespace is not explicitly supplied, the type will be added to a nameless global namespace.
Microsoft recommends that for most purposes you supply at least two nested namespace names: the first
one represents the name of your company, and the second one represents the name of the technology or
software package of which the class is a member, such as YourCompanyName.SalesServices.Customer.
This protects, in most situations, the classes in your application from possible name clashes with classes
written by other organizations.
No comments:
Post a Comment