Multiple files project in C#

S

schizoid_man

Hi,

I have a decent amount of programming experience in C/C++ and have
recently heard very good things about C#. So I decided to take a
look...

The lexical elements and language layout make it a little closer to
Java than to either C or C++, which is pretty interesting.

A question about a project that has say two .cs files. The first class
has the Main() method and the second class has got a non-static public
method called NormsDist().

If I instantiate both classes, how do I call NormsDist() from Main()?
In C++ I would have to include the method in a header file imported by
Main(), so how would the equivalent step work in C#?

Thanks in advance,
Schiz
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

schizoid_man said:
I have a decent amount of programming experience in C/C++ and have
recently heard very good things about C#. So I decided to take a
look...

The lexical elements and language layout make it a little closer to
Java than to either C or C++, which is pretty interesting.

A question about a project that has say two .cs files. The first class
has the Main() method and the second class has got a non-static public
method called NormsDist().

If I instantiate both classes, how do I call NormsDist() from Main()?
In C++ I would have to include the method in a header file imported by
Main(), so how would the equivalent step work in C#?

You need to do have an instance of the class to call the
method just like in C++.

But you do not need to do anything to have the functionality
available (like C++ include).

If it is in a different namespace then you can optionally
have a using statement.

Arne
 
S

schizoid_man

Arne said:
You need to do have an instance of the class to call the
method just like in C++.

But you do not need to do anything to have the functionality
available (like C++ include).

If it is in a different namespace then you can optionally
have a using statement.

Hi Arne,

The problem is - what if I have a really large project? It is
concievable that different classes could have the same method name(s)
and the same input parameters.

How would I control which methods are the ones used? Since there is no
method 'filtering' in the include file, would this be done simply by
using whichever objects have instantiated the respective
classes/methods?

Thanks.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

The problem is - what if I have a really large project? It is
concievable that different classes could have the same method name(s)
and the same input parameters.

How would I control which methods are the ones used? Since there is no
method 'filtering' in the include file, would this be done simply by
using whichever objects have instantiated the respective
classes/methods?

Classes with different names but same method signatures = no problem.

Classes with same name and same method signatures = problem, which
can and should be solved by using namespaces.

BTW, I do not think that is really so different from C++. Sure
you will not get a compile error if only you include one declaration
in the header files. But you will eventually get a link error.

Arne
 
S

schizoid_man

Arne said:
Classes with different names but same method signatures = no problem.

Classes with same name and same method signatures = problem, which
can and should be solved by using namespaces.

Yes, I suppose only the first situation should arise. Same names and
method signatures for different classes is probably poor design in any
case.
BTW, I do not think that is really so different from C++. Sure
you will not get a compile error if only you include one declaration
in the header files. But you will eventually get a link error.

Thanks for the help.
 
R

Richard Lewis Haggard

There are a few other little things to translate. In C++, we are used to
thinking in terms of DLL's and LIBs. No such thing exists in the .NET world.
Intead, we get 'assemblies' which are normally DLL's. There is no need to
include a link library to access the functionality. Intead, a 'reference' is
added to the solution. Since you are supplying all of the code in multiple
projects, the easiest thing may be to have a single solution with all of
your projects and then have your project include references to where the
namespaces for your redundantly named classes reside.
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

Arne said:
Classes with different names but same method signatures = no problem.

Classes with same name and same method signatures = problem, which
can and should be solved by using namespaces.

Yes, I suppose only the first situation should arise. Same names and
method signatures for different classes is probably poor design in any
case.
BTW, I do not think that is really so different from C++. Sure
you will not get a compile error if only you include one declaration
in the header files. But you will eventually get a link error.

Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top