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 7 1241
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*******@hotm ail.com> wrote in message
news:10******** *****@corp.supe rnews.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
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.mycl ass'
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
"Rob G" <gu*******@hotm ail.com> wrote in message news:10******** *****@corp.supe rnews.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
"myclass123 45" or "myclass123 46" ?)
Example: there is an Image class in namespace System.Drawing, but also
in System.Web.UI.W ebControls and System.Web.UI.M obileControls.
All three are different classes.
Hans Kesting
Just to add to the excellent descriptions from other responders:
For your first namespace, use something like "MyCompany.MyAp plication". 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.Libr ary.SubjectArea " (e.g. if your company is called
CoolCoders and you are writing a DLL dealing with Graphics manipulation,
then something like: CoolCoders.Libr ary.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*******@hotm ail.com> wrote in message
news:10******** *****@corp.supe rnews.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
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*******@hotm ail.com> wrote in message
news:10******** *****@corp.supe rnews.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
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*******@hotm ail.com> wrote in message
news:10******** *****@corp.supe rnews.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
Having the Using is optional. Say you want to run a process using the
Process Class which is stored in the System.Diagnost ics Namespace. You
could create the class like this:
System.Diagnost ics.Process proc = new System.Diagnost ics.Process();
However if you put "Using System.Diagnost ics" 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*******@hotm ail.com> wrote in message news:10******** *****@corp.supe rnews.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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 decided to forget about namespaces?
Why would they do this?
I could really use namespaces. If they canned this idea, that is quite a
disappointment :-/ Guess you cannot win them all.
|
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 a single
collections type, I should be proposing a new "namespaces" module
instead. Some of my reasons:
(1) Namespace is feeling less and less like a collection to me. Even
though it's still intended as a data-only structure, the use cases...
|
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 I am trying to use XML
Schemas to tell more about what kind of data are allowed on each
element/attribute, but I can't understand how to mix Namespaces and
Schemas.
Can anyone give me tips, starting points, about how to specify the
|
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
What's the difference here? Are there right and wrong namespaces? Is there
a global list of the ones to use? Does the namespace even need to point at
http://www.w3.org.....? Or is this just the accepted way?
|
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 generic code in C# and the cast operator overloading thing but one of the things I like about VB.NET is it doesn't enthrust the pointless idea of namespaces on you, even though I notice that you can have them if you want.
Are they turn-off-able?
| |
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 write a signature for the
developer and after getting a good start developing a 2.0 application I
thought I should go through the code and start marking classes and with
namespaces. I keep getting the following 'missing' error even when using a
first...
|
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)
<DOM Element: href at 0x1443e68>
>>> document.toxml()
'<?xml version="1.0" ?>\n<href/>'
Note that the namespace wasn't emitted. If I have PyXML,
|
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 gives me the following error:-
An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message:...
|
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 the schema
because it is going to reside in the same location as the xml file.
I am now working on a project that is a bit more complex. Again part
is a desktop application which will not have access to the Internet all
the time, but another...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |