Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Namespace concept

Posted on 2007-11-14
2
Medium Priority
?
659 Views
Last Modified: 2013-11-07
In asp.net, what is the concept of the Namespace?

I mean, I am looking at a Custom MembershipUser, at the top it has a Namespace of say, MyNameSpace....

within this MembershipUser, it implements a custom ObjectBase class, which also has the namespace MyNameSpace.

Then in this example I'm looking at, there are a couple of other custom classes and they have a namespace of, for example:

MyNameSpace.Stuff

Why do you create this "Stuff" sub namespace? What is that called anyway? and why?

I have read this:

http://msdn2.microsoft.com/en-us/library/0dx91cw5(VS.80).aspx

So please don't send me to a URL.

For instance.. it says:

>>causes the source code following the declaration to be compiled within that namespace

So what are the benefits of compiling into a namespace?

Just a one paragraph explanation explaining why you use it, the benefits, etc. Not looking for a book, just something you'd explain to a trainee at the coffee pot about namespaces in human language.

Now, in the above url, it says this:

>>Adding to a Namespace. If a namespace is already defined, even outside your project, you can add programming elements to it. To do this, you use a Namespace statement to direct Visual Basic to compile the following elements into that namespace.

It shows an example of using this namespace:

Namespace System.Collections.Generic

But that is an existing namespace. Why would you add to an existing System namespace?

0
Comment
Question by:Starr Duskk
2 Comments
 
LVL 37

Accepted Solution

by:
samtran0331 earned 1000 total points
ID: 20281703
>>In asp.net, what is the concept of the Namespace?
>>Why do you create this "Stuff" sub namespace? What is that called anyway? and why?
>>So what are the benefits of compiling into a namespace?

In my opinion, in practice, namespaces are just housekeeping.  
How do you want to group and organize your code?
Usage of namespaces (again, just in my experience) is going to be defined either by company standards or the developer.


>>Why would you add to an existing System namespace?

Again, just housekeeping.
If you write some code that manipulates text, do you want it in your own namespace and class and use it with something like "MyNamespace.MyTextFunctions.SomeFunction"
or do you feel it's good enough to be part of System.Text?
and then call it with "System.Text.MyTextFunctions.SomeFunction"
0
 
LVL 10

Assisted Solution

by:Oliver Amaya
Oliver Amaya earned 1000 total points
ID: 20281720
Hi,

A namespace is basically a way to group together classes that perform a common goal, or that have some kind of relationship between them, usually what I do is create one general namespace say MyApp and start distributing the classes that I use in my project in different sub-namespaces, something like MyApp.Data, MyApp.ErrorHandling, MyApp.Controls, etc. that way you get a nice separation of the different layers in the structure of your application.

I don't believe it's a good practice to add to any of the existing namespaces in the .NET framework, that would just create confusion to anybody using your classes and result in not being able to tell which assemblies are needed as references to a project in order to use them.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question