Alex Rivera | Logout

Console app arguments, how arguments are passed to Main method

Asked 2011-05-27T10:35:58.583
75

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)
        {    
        }
    }
}
Edit
Report

2 Answers

37

The Main method is the Entry point of your application. If you checkout via ildasm then

.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint

This is what helps in calling the method

The arguments are passed as say C:\AppName arg1 arg2 arg3

answered 2011-05-27T10:44:30.720
1

Every managed exe has a an entry point which can be seen when if you load your code to ILDASM. The Entry Point is specified in the CLR headed and would look something like this.

enter image description here

answered 2011-05-27T10:47:31.093

Your Answer