C# applications have an entry point called Main Method. It is the first method which gets invoked whenever an application started and it is present in every C# executable file. The application may be Console Application or Windows Application. The most common entry point of a C# program is static void Main() or static void Main(String [ ]args).
Different Declaration of Main() Method
Below are the valid declarations of Main Method in a C# program:
With command line arguments: This can accept n number of array type parameters during the runtime.
Example:
using System;
class GFG
{
// Main Method
static public void Main(String[] args)
{
Console.WriteLine("Main Method");
}
Meaning of the Main Syntax:
static: It means Main Method can be called without an object.
public: It is access modifiers which means the compiler can execute this from anywhere.
void: The Main method doesn’t return anything.
Main(): It is the configured name of the Main method.
String []args: For accepting the zero-indexed command line arguments. args is the user-defined name. So you can change it by a valid identifer. [] must come before the args otherwise compiler will give errors.
"command line arguments in c#"
"multiple main methods in c#"
"main method in c# console application"
"how to call main method in c#"
"how to return to main method in c#"
"program does not contain a static 'main' method suitable for an entry point"