473,388 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Trying to Understanding Namespaces

Hi,

I am having a problem finding a good explanation of exactly how Namespace
works. I am not clear on how it uses directories (if it does at all),
contains classes, after I complile a cs file how does a Namespace come into
play, or do I even need to have one?

Any info would be greatly appreciated.

Thanks so much.

-Rob
Nov 16 '05 #1
7 1226
Hi Rob,
The work pretty simple. They make the name of the classes longer, minimizing
the chanches (but not avoiding) of type name clashes. There is not
directories and whatsoever involved.

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Rob G" <gu*******@hotmail.com> wrote in message
news:10*************@corp.supernews.com...
Hi,

I am having a problem finding a good explanation of exactly how Namespace
works. I am not clear on how it uses directories (if it does at all),
contains classes, after I complile a cs file how does a Namespace come into play, or do I even need to have one?

Any info would be greatly appreciated.

Thanks so much.

-Rob

Nov 16 '05 #2
Rob,

A namespace does not use directories as such. But you can think of them
as directories to hold and organize classes, structs, enums and in fact
all types.

It works in the same way as a file system. Imagine if you had all your
files in one folder. No file could have the same name, there would be
100,000's of files and it would be impossible to find anything. A
namespace is the same thing. If you put a class in the namespace
mycompany and your class was called myclass. Then if you were to use
that class in another project then you would call that class as
'mycompany.myclass'

Yes you do have to have your objects within a namespace, but its totally
up to you how you arrange it. Microsoft has set some recommend i
believe (if they have i am sure you can find them on MSDN).

Try to have your namespaces logical. for example System.Text contains
classes which can be used for text manipulation. System.IO namespace
contains Input/Output objects.
One thing to note- don't use the system namespace.

Hope this helps a little bit.

-Arran

Rob G wrote:
Hi,

I am having a problem finding a good explanation of exactly how Namespace
works. I am not clear on how it uses directories (if it does at all),
contains classes, after I complile a cs file how does a Namespace come into
play, or do I even need to have one?

Any info would be greatly appreciated.

Thanks so much.

-Rob

Nov 16 '05 #3

"Rob G" <gu*******@hotmail.com> wrote in message news:10*************@corp.supernews.com...
Hi,

I am having a problem finding a good explanation of exactly how Namespace
works. I am not clear on how it uses directories (if it does at all),
contains classes, after I complile a cs file how does a Namespace come into
play, or do I even need to have one?

Any info would be greatly appreciated.

Thanks so much.

-Rob


Directories and namespaces are loosely coupled:
When you add an item to a subdirectory of a project, the namespace clause
that is generated is: project namespace + directory
(project has namespace A.B, subdir = C: new item gets A.B.C)
But the compiler doesn't complain when you change that namespace.

Namespaces are a way to organise your classes. Without them it would be difficult
to assign a meaningful name to a new item or to find a defined item. (did I need
"myclass12345" or "myclass12346" ?)

Example: there is an Image class in namespace System.Drawing, but also
in System.Web.UI.WebControls and System.Web.UI.MobileControls.
All three are different classes.
Hans Kesting

Nov 16 '05 #4
Just to add to the excellent descriptions from other responders:

For your first namespace, use something like "MyCompany.MyApplication". Use
the same namespace for all your classes (including the forms).
Then, you are unlikely to need to care again.

If you create a DLL, and your app calls that DLL, you will want to use a
namespace naming convention that you will find useful.

Like "MyCompany.Library.SubjectArea" (e.g. if your company is called
CoolCoders and you are writing a DLL dealing with Graphics manipulation,
then something like: CoolCoders.Library.Graphics )

Then, to use it in your application, set a reference to the DLL that
contains the classes you want and put a "using" statement (if you use C#) or
an imports statement (if you use VB) in each file where you want to
reference the classes.

Also note: you can have as many namespaces declared in a single DLL as you
want. In fact, you can have more than one namespace declared in a single
file. It's up to you.

Good Luck,
--- Nick

"Rob G" <gu*******@hotmail.com> wrote in message
news:10*************@corp.supernews.com...
Hi,

I am having a problem finding a good explanation of exactly how Namespace
works. I am not clear on how it uses directories (if it does at all),
contains classes, after I complile a cs file how does a Namespace come into play, or do I even need to have one?

Any info would be greatly appreciated.

Thanks so much.

-Rob

Nov 16 '05 #5
And just a little reminder. Don't overdo with the namespaces. If you write a
library that is going to be used by other programmers and you ask them 'how
to organize the namespaces' they mostlikely will say 'Put all the classes in
one namespace...' :) at least I will answer that. It is really anoying if I
have to go back and forth to the documentation to see in which namespace the
class is defined. Oranize them logically, but keep granularity minimum.

--

Stoitcho Goutsev (100) [C# MVP]
"Rob G" <gu*******@hotmail.com> wrote in message
news:10*************@corp.supernews.com...
Hi,

I am having a problem finding a good explanation of exactly how Namespace
works. I am not clear on how it uses directories (if it does at all),
contains classes, after I complile a cs file how does a Namespace come into play, or do I even need to have one?

Any info would be greatly appreciated.

Thanks so much.

-Rob

Nov 16 '05 #6
All,

Thanks for the great responses. Everyone consolidated the information I need
in a way that I finally understood.

If I may ask another question...

The "Using" keyword is the way to use the classes in a namespace. Is that
correct?

Could anyone give me a quick example of using a Namespace?

Thanks again.

-Rob
"Rob G" <gu*******@hotmail.com> wrote in message
news:10*************@corp.supernews.com...
Hi,

I am having a problem finding a good explanation of exactly how Namespace
works. I am not clear on how it uses directories (if it does at all),
contains classes, after I complile a cs file how does a Namespace come into play, or do I even need to have one?

Any info would be greatly appreciated.

Thanks so much.

-Rob

Nov 16 '05 #7
Having the Using is optional. Say you want to run a process using the
Process Class which is stored in the System.Diagnostics Namespace. You
could create the class like this:

System.Diagnostics.Process proc = new System.Diagnostics.Process();

However if you put "Using System.Diagnostics" then you can create the
Process class like this:

Process proc = new Process();

Having the 'Using' is like shorthand.
Rob G wrote:
All,

Thanks for the great responses. Everyone consolidated the information I need
in a way that I finally understood.

If I may ask another question...

The "Using" keyword is the way to use the classes in a namespace. Is that
correct?

Could anyone give me a quick example of using a Namespace?

Thanks again.

-Rob
"Rob G" <gu*******@hotmail.com> wrote in message
news:10*************@corp.supernews.com...
Hi,

I am having a problem finding a good explanation of exactly how Namespace
works. I am not clear on how it uses directories (if it does at all),
contains classes, after I complile a cs file how does a Namespace come


into
play, or do I even need to have one?

Any info would be greatly appreciated.

Thanks so much.

-Rob


Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Joshua Beall | last post by:
Hi All, I read in a forum somewhere that namespaces, though once supposed to be a part of PHP5, have been removed. Is this true? Can anyone show me the official statement by Zend that they...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
6
by: inerte | last post by:
Hello all! I need to build an XML file structure so a client can import data to one of our systems. Totally new to XML, I learned about Namespaces and DTD, and built a nice spec using them. Now...
2
by: Mike Morse | last post by:
What see sample that show xs:element where the xs namespace = http://www.w3.org/2001/XMLSchema However, I see another example with xsi: where xsi = http://www.w3.org/2001/XMLSchema-instance ...
2
by: Beeeeeeeeeeeeves | last post by:
Does C# really HAVE to have namespaces? Isn't there any way I can turn them off? I did a bit of dabbling in VB.NET but have decided not to switch to it permanantly as I've got too much pre-written...
17
by: clintonG | last post by:
Using 2.0 with Master Pages and a GlobalBaseClass for the content pages. I understand the easy part -- the hierarchical structure of a namespace naming convention -- but the 2.0 IDE does not...
36
by: Wilfredo Sánchez Vega | last post by:
I'm having some issues around namespace handling with XML: >>> document = xml.dom.minidom.Document() >>> element = document.createElementNS("DAV:", "href") >>> document.appendChild(element)...
2
by: msnews.microsoft.com | last post by:
I am currently trying to follow the Que Publishing exam guide to the Microsoft Exam 70-320. I followed the guide to a tee, but when I try to add a web reference to my server side soap extension it...
7
by: cartoper | last post by:
XML, Schemas, and XSLT has been part of my life for a number of years now, but I have always used it in desktop application where I simply make the noNamespaceSchemaLocation attribute the name of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.