This would be question from c# beginner. When I create console application I get Main method with parameter args as array string. I do not understand how this method is called by system and how args are passed to the Main method. Maybe someone could explain? Is Main method are overridden of some kind of console class?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
}
}
in visual studio you can also do like that to pass simply or avoiding from comandline argument
When you are using the console application template the code will be compiled requiring a method called Main in the startup object as Main is market as entry point to the application.
By default no startup object is specified in the project propery settings and the Program class will be used by default. You can change this in the project property under the "Build" tab if you wish.
Keep in mind that which ever object you assign to be the startup object must have a method named Main in it.
The accepted format is MyConsoleApp.exe value01 value02 etc...
The application assigns each value after each space into a separate element of the parameter array.
Thus, MyConsoleApp.exe value01 value02 will mean your args paramter has 2 elements:
How you parse the input values and use them is up to you.
Hope this helped.
Additional Reading:
Creating Console Applications (Visual C#)
Command-Line Arguments (C# Programming Guide)
The main method of the runtime engine looks something like
int main(int argc, char *argv[])
, where argc is a count of the number of arguments and argv is an array of pointers to each. The runtime engine converts this into a form that is more natural to c#.Prior to that main method being called, everything is in assembly language. It has access to the command line arguments (because the operating system makes that available to every process that starts), but that assembly language needs to convert a single string of the full command line into multiple substrings (using whitespace to separate them) before it's ready to pass them into main().
The runtime splits the arguments given at the console at each space.
If you call
The Main Method gets an array of
Command line arguments is one way to pass the arguments in. This msdn sample is worth checking out. The MSDN Page for command line arguments is also worth reading.
From within visual studio you can set the command line arguments by Choosing the properties of your console application then selecting the Debug tab