Console app arguments, how arguments are passed to Main method

Tomas picture Tomas · May 27, 2011 · Viewed 115.7k times · Source

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

Answer

Basheer AL-MOMANI picture Basheer AL-MOMANI · Jul 13, 2016

All answers are awesome and explained everything very well

but I just want to point out different way for passing args to main method

in visual studio

  1. right click on Project then choose Properties
  2. go to Debug tab then on the Start Options section provide the app with your args

like this image

Properties window

and happy knowing secrets