Static Keyword
What is use of Static keyword under Main method
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit Kumar SinghRank #562 · 4.3K reputationPosted Apr 29, 2016, 1:50 AM EDT
You need an entry point into your program. Static means that you can call the function without having to instantiate an object/instance of a class. Its a bit "chicken and egg"... you can't instantiate an object before you're inside the program.
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.
the keywordstaticto the function definition to change it. Its worth looking into static (class) methods vs instance methods, and knowing the difference can be useful at times.Vivek KumarRank #272 · 9.3K reputationPosted Apr 29, 2016, 8:27 AM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted May 1, 2016, 7:51 AM EDT
You need an entry point into your program. Static means that you can call the function without having to instantiate an object/instance of a class. Its a bit "chicken and egg"... you can't instantiate an object before you're inside the program.
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.
As David says you can just add the keyword
staticto the function definition to change it. Its worth looking into static (class) methods vs instance methods, and knowing the difference can be useful at times.Bhuvanesh MohankumarRank #310 · 8.1K reputationPosted May 4, 2016, 1:56 AM EDT
Accept as answer, if it was helpful.