private static void Main()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In Java, the Main method cannot have any other access modifier than 'public'. How is it that in C# you can have a private access modifier to the Main method ? Can anybody throw any light, comparing JVM with CLR

Thanks
Sujala
 
Hi,

If you refer to Main method as the entry point of the application, then you
have a similar situation in C# than in Java, in c# the entry point MUST be
declared as
static void Main() , if that is not present the compiler will give you an
error.

Now there is nothing that prohibite you to name a method Main() on any
class, only that it will no be the entry point of the application.


Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Sujala said:
In Java, the Main method cannot have any other access modifier than
'public'. How is it that in C# you can have a private access modifier to the
Main method ? Can anybody throw any light, comparing JVM with CLR ?
 
Ignacio,

Thanks for your answer. But its not true that "in c# the entry point
MUST be declared as static void Main() , if that is not present the
compiler will give you an error." Infact it works even if you declare
the entry point as "private static void Main()" , the compiler gives no
error, neither the CLR throws any run-time error !!! Isnt this strange
??!! Thats precisely the point of confusion. You may try this out.


Thanks,
Sujala
 
Sujala,

public, private, protected and others are access attributes that are
enforced primarily by the compiler (at runtime only when dynamic invocation
is involved). Beyond that, the runtime is free to accept or ignore the
access specifiers - and in the case of Main, it kindly ignores them.

Matters such as these (and this is but one example of many others) are
implementation specific details for the runtime, not for a particular
language.

regards
roy fine


Sujala said:
In Java, the Main method cannot have any other access modifier than
'public'. How is it that in C# you can have a private access modifier to the
Main method ? Can anybody throw any light, comparing JVM with CLR ?
 
Back
Top