using namespaces in C# (newbie)

  • Thread starter Thread starter Svein Erik Storkaas
  • Start date Start date
S

Svein Erik Storkaas

I'm having problem using namespaces in C#...

It's like it is being ignored no matter what i use..does'nt seem to work.
Can anyone give a small sample code just how to use it?

thanx
 
A namespace is just a handy way of collecting your code under one (or
more) name. If you are referring to
using System.Drawing; and so on, you don't really need them, but you do
need to add a reference, if there isn't one already.
In Visual Studio, Choose Solution Explorer, right click on references and
Add.
On the command line you add /reference: some.dll
 
Hi,

You could take a look on (for more details about using namespaces):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html
/vclrfcsharpspec_9_3_2.asp

You may think as the namespace being a part of your class name.
E.g. Having Class1 defined in Namespace1, you can use it in 2 ways:

1. Namespace1.Class1

Namespace1.Class1 myclass = new Namespace1.Class1();

2. By Adding a using directive:
using Namespace1;
Class1 myclass = new Class1();

The "using" directive is more like a shortcut, because you don't have to
type the full class name (including the namespace) all the time.

I'm having problem using namespaces in C#...

It's like it is being ignored no matter what i use..does'nt seem to work.
Can anyone give a small sample code just how to use it?

thanx

Regards,
Adrian Vinca [MSFT]
 
Back
Top