Solved

Namespace concept

Posted on 2007-11-14
2
649 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:BobCSD
2 Comments
 
LVL 37

Accepted Solution

by:
samtran0331 earned 250 total points
Comment Utility
>>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:joex911
joex911 earned 250 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now