Solved

Namespace concept

Posted on 2007-11-14
2
650 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 250 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:joex911
joex911 earned 250 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

776 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