user2329702
user2329702

Reputation: 479

The way of working of c# main method

In Java , generally we declare main method as public because it should be availbale out of class for JVM to execute.

But in c# , we declare main method as private ( default access specifier is private for method in c#). How main method is available to CLR to get executed?

Please forgive me for asking very simple question :)

Upvotes: 2

Views: 84

Answers (2)

user937999
user937999

Reputation:

Access (Public, Private) modifiers are just for developers to prevent using unwanted methods or members. VM just needs a method to start execute your program regardless of its access modifier.

Upvotes: 1

vish1990
vish1990

Reputation: 384

The CLR doesn't actually mind if your method is private or public. It doesn't invoke it through the use of normal C# code.In native Call stack,CLR gets to Main method using .entrypoint IL directive

Upvotes: 6

Related Questions