- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why is the Main() method use in C# static?
The Main method states what the class does when executed and instantiates other objects and variables.
A main method is static since it is available to run when the C# program starts. It is the entry point of the program and runs without even creating an instance of the class.
The following shows how to add a Main() method with static −
Example
using System; namespace Demo { class HelloWorld { static void Main(string[] args) { Console.WriteLine("Bingo!"); Console.ReadKey(); } } }
Output
Bingo!
As you can see in the above example −
static void Main(string[] args) {
Here,
static − the object is not needed to access static members
void − return type of the method
Main − entry point for any C# program. Program execution begins here.
string[] args − for command line arguments in C#.
- Related Articles
- Why the main () method in Java is always static?
- Why main() method must be static in java?
- How to use the Main() method in C#?
- Why can't we use the "super" keyword is in a static method in java?
- Can We declare main() method as Non-Static in java?
- How to execute a static block without main method in Java?
- What is the use of static constructors in C#?
- Static vs. Non-Static method in C#
- Can we change the order of public static void main() to static public void main() in Java?
- Why the main method has to be in a java class?
- Is main method compulsory in Java?
- Why can't static method be abstract in Java?
- Why "this" keyword cannot be used in the main method of java class?
- Can we use "this" keyword in a static method in java?
- Why is there no main() function in Python?

Advertisements