

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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#.
- Related Questions & Answers
- Why is the Main() method use in C# static?
- Can we overload the main method in Java?
- Can we override the main method in java?
- What is the main use of Ruby programming?
- Is main method compulsory in Java?
- Why the main () method in Java is always static?
- Can the main method in Java return a value?
- Why the main method has to be in a java class?
- How to use the sleep method in C#?
- How to execute a static block without main method in Java?
- Can we overload Java main method?
- Can we declare the main () method as final in Java?
- How to use the then method in Rest Assured?
- How command line arguments are passed in main method in C#?
- How to call the main function in C program?
Advertisements