have main as private

T

Tony Johansson

Hello!

I just wonder why many books and some other decument on the net says that "A
main method must always be declared public and static"

I agree that main must always be static but the runtime simply ignore if you
declare main to be privat it works just as good
as if you have declared it as public.

//Tony
 
P

Patrice

Hello,

Could be perhaps an habit carried over from other languages ? For example
java seems to make public a requirement :
http://java.sun.com/docs/books/tutorial/getStarted/application/index.html#MAIN.

The C# doc doesn't seems to tell this and would rather promote the opposite
:
"Main must be static and it should not be public".
from http://msdn.microsoft.com/en-us/library/acy3edy3.aspx

So a book author used to other languages could quite easily carry over his
knowledge to C# without noticing the difference...
 
A

Arne Vajhøj

I just wonder why many books and some other decument on the net says that "A
main method must always be declared public and static"

I agree that main must always be static but the runtime simply ignore if you
declare main to be privat it works just as good
as if you have declared it as public.

Which is very good to know if you are entering an obfuscated code
contest.

But if you plan to write easy to read code, then it makes sense
to make something that is to be called externally as public.

Arne
 
P

Peter Duniho

Tony said:
Hello!

I just wonder why many books and some other decument on the net says that "A
main method must always be declared public and static" [...]

Because most references fail to get every single fact they attempt to
state correct. You just can't expect to believe everything you read.

I wouldn't even hold it against them too much. That's the sort of thing
that could be easily checked, but the more things one tries to explain,
the greater the chance some mistake will slip through.

Just keep your eyes open, don't take anything as the gospel truth, and
you'll be fine.

Pete
 

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