1)The Main method is the entry point of an executable program; it is where the program control starts and ends.
2)Main is declared inside a class or struct. Main must be static and it need not be public. (In the earlier example, it receives the default access of private.) The enclosing class or struct is not required to be static.
3) Main can either have a void, int, or, starting with C# 7.1, Task, or Task return type.
4)If and only if Main returns a Task or Task, the declaration of Main may include the async modifier. This specifically excludes an async void Main method.
5)The Main method can be declared with or without a string[] parameter that contains command-line arguments. When using Visual Studio to create Windows applications, you can add the parameter manually or else use the GetCommandLineArgs() method to obtain the command-line arguments. Parameters are read as zero-indexed command-line arguments. Unlike C and C++, the name of the program is not treated as the first command-line argument in the args array, but it is the first element of the GetCommandLineArgs() method.
Command-Line Arguments:
You can send arguments to the Main method by defining the method in one of the following ways:
The parameter of the Main method is a String array that represents the command-line arguments. Usually you determine whether arguments exist by testing the Length property, for example:
if (args.Length == 0)
{
System.Console.WriteLine("Please enter a numeric argument.");
return 1;
}
The args array can't be null. So, it's safe to access the Length property without null checking.
You can also convert the string arguments to numeric types by using the Convert class or the Parse method. For example, the following statement converts the string to a long number by using the Parse/Convert method:
Rajanikant HawaldarPosted Aug 20, 2022, 7:25 AM
https://www.c-sharpcorner.com/UploadFile/3d39b4/command-line-arguments-in-C-Sharp/
Main method:
1)The Main method is the entry point of an executable program; it is where the program control starts and ends. return type., the declaration of Main may include the async modifier. This specifically excludes an async void Main method.
2)Main is declared inside a class or struct. Main must be static and it need not be public. (In the earlier example, it receives the default access of private.) The enclosing class or struct is not required to be static.
3) Main can either have a void, int, or, starting with C# 7.1, Task, or Task
4)If and only if Main returns a Task or Task
5)The Main method can be declared with or without a string[] parameter that contains command-line arguments. When using Visual Studio to create Windows applications, you can add the parameter manually or else use the GetCommandLineArgs() method to obtain the command-line arguments. Parameters are read as zero-indexed command-line arguments. Unlike C and C++, the name of the program is not treated as the first command-line argument in the args array, but it is the first element of the GetCommandLineArgs() method.
Command-Line Arguments:
You can send arguments to the Main method by defining the method in one of the following ways:
--Main signature--
static void Main(string[] args) Main(string[] args)
static int Main(string[] args)
static async Task Main(string[] args)
static async Task
If the arguments are not used, you can omit args from the method signature for slightly simpler code:
--Main signature--
static void Main() Main()
static int Main()
static async Task Main()
static async Task
The parameter of the Main method is a String array that represents the command-line arguments. Usually you determine whether arguments exist by testing the Length property, for example:
The args array can't be null. So, it's safe to access the Length property without null checking.
You can also convert the string arguments to numeric types by using the Convert class or the Parse method. For example, the following statement converts the string to a long number by using the Parse/Convert method:
Brahma Prakash ShuklaPosted Nov 11, 2022, 8:29 AM
https://www.geeksforgeeks.org/c-sharp-command-line-arguments/