473,320 Members | 1,823 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,320 software developers and data experts.

Classes and Namespaces

In Vb a class was a file, but in C# you have multiple classes in one file
which
has a namespace.

I am trying to get some common code libraries written but this is stuffing
my head up.

Is it normal in C# to have a namespace for each class file or isn't it a
class

I now need to call like this

<MyNameSpace contained in class file that I added to a solution .
MyClassName> myclassName = new <1st Part>

Is this normal I AM SO CONFUSED (Any help welcome!)

Regards

Michael

Nov 15 '05 #1
6 1792
Michael,

Both c# and vb.net have the idea of a Namespace.
In simple terms, think of a Namespace as a hierarchal organization of your
classes. If you look at the MS .Net Framework, all the classes are
organized by the sort of thing they are used for (kind of like the way you
organize files in a directory structure so you know were to find the
specific file you are looking for without having all files sitting at c:\).
System.Data is all the data stuff, System.IO is all the stream and file io
stuff. We use namespaces in our code for the same reason, just to organize
the classes into something that is easier to deal with.

In C#, each file in the project can have 1 or more classes. Usually, each
file has a Namespace that encloses the class(es) in the file. That same
Namespace can be used in other files as well.

The important part to remember is that Namespaces are not objects, just a
way of organizing things (I expect I will take some flak for that last
statement, but without making things too complicated it is basicly true.)

Kirk Graves
KRGIT Software

"Michael C" <as***@askme.com> wrote in message
news:OU****************@TK2MSFTNGP12.phx.gbl...
In Vb a class was a file, but in C# you have multiple classes in one file
which
has a namespace.

I am trying to get some common code libraries written but this is stuffing
my head up.

Is it normal in C# to have a namespace for each class file or isn't it a
class

I now need to call like this

<MyNameSpace contained in class file that I added to a solution .
MyClassName> myclassName = new <1st Part>

Is this normal I AM SO CONFUSED (Any help welcome!)

Regards

Michael

Nov 15 '05 #2
Michael,

Both c# and vb.net have the idea of a Namespace.
In simple terms, think of a Namespace as a hierarchal organization of your
classes. If you look at the MS .Net Framework, all the classes are
organized by the sort of thing they are used for (kind of like the way you
organize files in a directory structure so you know were to find the
specific file you are looking for without having all files sitting at c:\).
System.Data is all the data stuff, System.IO is all the stream and file io
stuff. We use namespaces in our code for the same reason, just to organize
the classes into something that is easier to deal with.

In C#, each file in the project can have 1 or more classes. Usually, each
file has a Namespace that encloses the class(es) in the file. That same
Namespace can be used in other files as well.

The important part to remember is that Namespaces are not objects, just a
way of organizing things (I expect I will take some flak for that last
statement, but without making things too complicated it is basicly true.)

Kirk Graves
KRGIT Software

"Michael C" <as***@askme.com> wrote in message
news:OU****************@TK2MSFTNGP12.phx.gbl...
In Vb a class was a file, but in C# you have multiple classes in one file
which
has a namespace.

I am trying to get some common code libraries written but this is stuffing
my head up.

Is it normal in C# to have a namespace for each class file or isn't it a
class

I now need to call like this

<MyNameSpace contained in class file that I added to a solution .
MyClassName> myclassName = new <1st Part>

Is this normal I AM SO CONFUSED (Any help welcome!)

Regards

Michael

Nov 15 '05 #3
Hi Michael,
Every class belong to a namespace. This is usefull, because now you may have
classes with equal names, which belongs to different namespaces, and behave
differently without any confusion for the compiler or the user of your
class. As an example, assume that you have 2 namespaces: TCPcomunications
and HTTPcomunications. Now in every namespace you can create
ConnectionClass, and it will be different for evry namespace.
And in your code you can clearly identify the exact class you want to use:
TCPcomunications.ConnectionClass or HTTPcomunications.ConnectionClass.

You can have nested namespaces, like MyCompany.MyFirstProject.BaseObjects.
If you create a class in that namespace - MyClass, this class will be
completeley different from the class MyClass, created by someone else in
other namespace(s), and in your code you can be sure that you are using the
right one.

Also, if you do not want in your code always to type:
MyCompany.MyFirstProject.BaseObjects.MyClass, you can use the "using"
keyword:

using MyCompany.MyFirstProject.BaseObjects

.... and later in the code, you can use:
MyClass obj = new MyClass;

Hope that helps
Sunny
Michael C wrote:
In Vb a class was a file, but in C# you have multiple classes in one file
which
has a namespace.

I am trying to get some common code libraries written but this is stuffing
my head up.

Is it normal in C# to have a namespace for each class file or isn't it a
class

I now need to call like this

<MyNameSpace contained in class file that I added to a solution .
MyClassName> myclassName = new <1st Part>

Is this normal I AM SO CONFUSED (Any help welcome!)

Regards

Michael

Nov 15 '05 #4
Hi Michael,
Every class belong to a namespace. This is usefull, because now you may have
classes with equal names, which belongs to different namespaces, and behave
differently without any confusion for the compiler or the user of your
class. As an example, assume that you have 2 namespaces: TCPcomunications
and HTTPcomunications. Now in every namespace you can create
ConnectionClass, and it will be different for evry namespace.
And in your code you can clearly identify the exact class you want to use:
TCPcomunications.ConnectionClass or HTTPcomunications.ConnectionClass.

You can have nested namespaces, like MyCompany.MyFirstProject.BaseObjects.
If you create a class in that namespace - MyClass, this class will be
completeley different from the class MyClass, created by someone else in
other namespace(s), and in your code you can be sure that you are using the
right one.

Also, if you do not want in your code always to type:
MyCompany.MyFirstProject.BaseObjects.MyClass, you can use the "using"
keyword:

using MyCompany.MyFirstProject.BaseObjects

.... and later in the code, you can use:
MyClass obj = new MyClass;

Hope that helps
Sunny
Michael C wrote:
In Vb a class was a file, but in C# you have multiple classes in one file
which
has a namespace.

I am trying to get some common code libraries written but this is stuffing
my head up.

Is it normal in C# to have a namespace for each class file or isn't it a
class

I now need to call like this

<MyNameSpace contained in class file that I added to a solution .
MyClassName> myclassName = new <1st Part>

Is this normal I AM SO CONFUSED (Any help welcome!)

Regards

Michael

Nov 15 '05 #5
Hi

So I could use the using statement as long as the class name didn't exist in
another namespace otherwise I would get a compile error correct (Correct?)

And also if I create a dll should I use the same name as the namespace
within the dll correct!

But what happens if I have the following MyDllName added as a reference to a
solution and
2 namespaces within that Dll ... or is that usually not good coding
practice?

Regards

Michael
"Sunny" <su******@icebergwireless.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi Michael,
Every class belong to a namespace. This is usefull, because now you may have classes with equal names, which belongs to different namespaces, and behave differently without any confusion for the compiler or the user of your
class. As an example, assume that you have 2 namespaces: TCPcomunications
and HTTPcomunications. Now in every namespace you can create
ConnectionClass, and it will be different for evry namespace.
And in your code you can clearly identify the exact class you want to use:
TCPcomunications.ConnectionClass or HTTPcomunications.ConnectionClass.

You can have nested namespaces, like MyCompany.MyFirstProject.BaseObjects.
If you create a class in that namespace - MyClass, this class will be
completeley different from the class MyClass, created by someone else in
other namespace(s), and in your code you can be sure that you are using the right one.

Also, if you do not want in your code always to type:
MyCompany.MyFirstProject.BaseObjects.MyClass, you can use the "using"
keyword:

using MyCompany.MyFirstProject.BaseObjects

... and later in the code, you can use:
MyClass obj = new MyClass;

Hope that helps
Sunny
Michael C wrote:
In Vb a class was a file, but in C# you have multiple classes in one file which
has a namespace.

I am trying to get some common code libraries written but this is stuffing my head up.

Is it normal in C# to have a namespace for each class file or isn't it a
class

I now need to call like this

<MyNameSpace contained in class file that I added to a solution .
MyClassName> myclassName = new <1st Part>

Is this normal I AM SO CONFUSED (Any help welcome!)

Regards

Michael


Nov 15 '05 #6
Hi

So I could use the using statement as long as the class name didn't exist in
another namespace otherwise I would get a compile error correct (Correct?)

And also if I create a dll should I use the same name as the namespace
within the dll correct!

But what happens if I have the following MyDllName added as a reference to a
solution and
2 namespaces within that Dll ... or is that usually not good coding
practice?

Regards

Michael
"Sunny" <su******@icebergwireless.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi Michael,
Every class belong to a namespace. This is usefull, because now you may have classes with equal names, which belongs to different namespaces, and behave differently without any confusion for the compiler or the user of your
class. As an example, assume that you have 2 namespaces: TCPcomunications
and HTTPcomunications. Now in every namespace you can create
ConnectionClass, and it will be different for evry namespace.
And in your code you can clearly identify the exact class you want to use:
TCPcomunications.ConnectionClass or HTTPcomunications.ConnectionClass.

You can have nested namespaces, like MyCompany.MyFirstProject.BaseObjects.
If you create a class in that namespace - MyClass, this class will be
completeley different from the class MyClass, created by someone else in
other namespace(s), and in your code you can be sure that you are using the right one.

Also, if you do not want in your code always to type:
MyCompany.MyFirstProject.BaseObjects.MyClass, you can use the "using"
keyword:

using MyCompany.MyFirstProject.BaseObjects

... and later in the code, you can use:
MyClass obj = new MyClass;

Hope that helps
Sunny
Michael C wrote:
In Vb a class was a file, but in C# you have multiple classes in one file which
has a namespace.

I am trying to get some common code libraries written but this is stuffing my head up.

Is it normal in C# to have a namespace for each class file or isn't it a
class

I now need to call like this

<MyNameSpace contained in class file that I added to a solution .
MyClassName> myclassName = new <1st Part>

Is this normal I AM SO CONFUSED (Any help welcome!)

Regards

Michael


Nov 15 '05 #7

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

Similar topics

26
by: Joshua Beall | last post by:
Hi All, I remember reading that both nested classes and namespaces would be available in PHP5. I know that namespaces got canceled (much sadness...), however, I *thought* that nested classes...
7
by: Bora | last post by:
I usually find that a number of unrelated classes require the same kind of operations. However, I don't want to duplicate code in multiple places. In Java, I've seen those "Utility Classes",...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
3
by: jason | last post by:
Please pardon my completely lack of understanding on the topic. I have a website I developed with another developer. We are both far from experts in VB.NET and OOP. We developed the site WITHOUT...
5
by: Alex | last post by:
Hi, this is my first mail to the list so please correct me if Ive done anything wrong. What Im trying to figure out is a good way to organise my code. One class per .py file is a system I like,...
5
by: yads12 | last post by:
We have a webservice that is a passthrough to a third party webservice. The third party webservice uses the classes that are named the same for both the submission and result message. We have...
3
by: taps128 | last post by:
I've been reading the namespace specification for the 5.3 relaese, and I can't stop thinking that they have complicated the thing unecessary. Here is what I mean. So far if you call a function...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.