![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
How to use the Main() method in C#?
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 Main method states what the class does when executed and instantiates other objects and variables.
The following shows how to add a Main() method.
Example
using system; namespace demo { class helloworld { static void main(string[] args) { console.writeline("hello world"); console.readkey(); } } }
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#.
Advertisements