Main and accessibility...

I want to take in evidence an interesting question launched by Adrian Florea on UgiDotNet: what's the reasons to have a Main method not public???

Adrian points the attention to the differences between the last specifications of Java and C#:

C# Language Specification, 2nd editionJava Language Specification, 2nd edition
10.1
"Specifically, the execution environment can access the application’s entry point regardless of its declared accessibility and regardless of the declared accessibility of its enclosing type declarations."
12.1.4
"The method main must be declared public, static, and void. It must accept a single argument that is an array of strings"

Any explanations? Thanks Adrian for the question...

Print | posted on Saturday, July 31, 2004 6:31 AM

Comments on this post

# re: Main and accessibility...

Requesting Gravatar...
I'm trying a self-response... :-)

The "Main" method is decorated in IL with the ".entrypoint" directive. In IL, in fact, doesn't matter the name of the Main, so you could have (in C# for example) 2 valid "Main"s (valid as signature) and specify to the compiler the entry point through the "/main" option. But if you are writing the IL directly (I think...) you can decorate your Foo method with .entrypoint. So the "Main" method is in fact an aspect.

Now, I have another "Main"-related question: why in the IL generated signature of Main we have "hidebysig" (hides base class method of exact signature)?
Left by Adrian Florea on Aug 07, 2004 5:03 AM

# Decorando con .entrypoint

Requesting Gravatar...
Left by Web Log di Adrian Florea on Aug 27, 2004 4:42 AM

Your comment:

 (will show your gravatar)
 
Please add 1 and 7 and type the answer here: