+ 1

Main Method in C#

Why is the main method in C# static?

10th Dec 2017, 4:34 PM
Patryk Orlik
Patryk Orlik - avatar
4 Respostas
+ 9
A static method can be called without instantiating an object. Therefore main() needs to be static in order to allow it to be the entry to your program. To make it more clear, go through the official C# documentation: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/
10th Dec 2017, 4:41 PM
Dev
Dev - avatar
+ 9
@Patryk: Have a look at the link above, it makes it clearer. Though, you might need to check this out, too: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/static
10th Dec 2017, 4:48 PM
Dev
Dev - avatar
+ 2
What do u mean "Therefore main() needs to be static in order to allow it to be the entry to your program"?
10th Dec 2017, 4:43 PM
Patryk Orlik
Patryk Orlik - avatar
+ 2
Thank you :)
10th Dec 2017, 4:49 PM
Patryk Orlik
Patryk Orlik - avatar