Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 19th, 2003, 05:39 AM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default namespace

Hi...

I do not understand what the keyword 'namespace' is used for. For example...

// csharp program
namespace Timer
{
     class .....
     ....
}

I am infact used to packages in Java..... to be able to create a package..... it must be added to the first line of the code for example............

// Java program
package newPackage;

class ...
....

Is it a similar concept..... if not how do we declare namespaces (packages?) in C#...........

thanks,
Ibn_Aziz
Reply With Quote
  #2 (permalink)  
Old December 21st, 2003, 11:18 AM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Again answering my own questions.....

The namespace keyword is in reality used like the package keyword in JAva... basically to organise into a hierarchical structure of code....

ie

namespace ExampleOfNamespaces
{
     namespace ClassA
     {
          public ClassA
          {
                 ...
           }
     }

     namespace ClassB
     {
           public ClassB
           {
                ....
           }
      }
}


Then to be able to use class A, one would have to specify...

using ExampleOfNamespaces.ClassA;

Likewise to ab able to use class B one would have to specify

using ExampleOfNamespaces.ClassB;

One thing to bear in mind is that namepsace elements cannot explicitly be decalared as other than 'public'.

so this would cause an error....

namespace Trial
{
    private class box //error because only public allowed
    {
        ...
    }
}
Reply With Quote
  #3 (permalink)  
Old December 25th, 2003, 05:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Namespaces have a few more advantages than you have mentioned here. Like a namspace definition can span more than a single file. using namespaces you can resolve issues like how to use my Class A and smith's Class A in the same program, use the namesapces they are defines in to differentiate between them. I've been going through your queries and I would say that to appease the inquisitive mind that you possess you must get hold of a good book on C#. Professional C# would prove to be a good book for you.
Write back if there is anything else you wanna ask.

Ankur Verma
.Net and C++ Specialist
Wiley Tech Support
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two namespace contain same name nir_pankaj C# 1 February 21st, 2007 12:30 PM
Namespace ~Bean~ Classic ASP Basics 2 June 3rd, 2005 02:31 PM
namespace within namespace Bill Crawley XML 1 December 11th, 2003 10:59 AM
Namespace flute Pro VB.NET 2002/2003 2 October 21st, 2003 09:15 AM



All times are GMT -4. The time now is 07:51 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.