Solved

Namespace concept

Posted on 2007-11-14
2
652 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Oliver Amaya
Oliver Amaya 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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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