File name vs Class name - don't need to match like java?

R

Richard Muller

Hi All,

I wrote a HelloWorld.cs with HelloWorld class - I compiled it and it ran
fine.

I wanted to confirm that a class name had to match the file name, so I:
- copied the .cs file to HelloWorld2.cs
- compiled the new .cs and got HelloWorld2.exe (javac would have balked in a
similar situation)
- ran the .exe and it ran fine.

So is it generally true that no match between class name and file name must
exist?

--
TIA,
Richard

640K ought to be enough for anybody.
Bill Gates, 1981
 
R

Richard Muller

Hi Daniel,

Thanks for the confirmation.

After I posted my question, I found the /main switch which handles the
exceptional case that more than one class containing a static void Main(),
in which case the ambiguity must be resolved with /main:classname.

I also found that the output file name is taken from the source file that
contains the relevant static void Main(), unless a /out option is provided:
/out:filename.

I feel like I'm on a little firmer ground now, until I hit my next
quagmire.

Again, thanks for your help.

Regards,
Richard Muller
 
G

Grant Richins [MS]

And you can even have as many classes in one source file as you want (nested
or non-nested).
 
R

Richard Muller

Hi Gentlemen,

Thanks for the confirmation.

After I posted my question, I hunted through the VS.Net's help system and
found additional info that was helpful.

I found the /main switch which handles the exceptional case that more than
one class containing a static void Main(), in which case the ambiguity must
be resolved with /main:classname.

I also found that the output file name is taken from the source file that
contains the relevant static void Main(), unless an /out:filename option is
provided.

I feel like I'm on a little firmer ground now, until I hit my next
quagmire.

Again, many thanks to both of you for your help.

Regards,
Richard Muller
 

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