Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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
  #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
    {
        ...
    }
}
  #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


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





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