473,386 Members | 1,720 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,386 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 1794
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
jinu1996
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...

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.