In C #, getting command line arguments directly from Main () excludes the exe name, unlike the C tradition.
Getting the same command line commands through Environment.GetCommandLineArgs enables it.
Is there some good logical reason why I miss this apparent inconsistency?
class Program { static void Main(string[] args) { Console.WriteLine(string.Format("args.Length = {0}", args.Length)); foreach(string arg in args) { Console.WriteLine(string.Format("args = {0}", arg)); } Console.WriteLine(""); string[] Eargs = Environment.GetCommandLineArgs(); Console.WriteLine(string.Format("Eargs.Length = {0}", Eargs.Length)); foreach (string arg in Eargs) { Console.WriteLine(string.Format("Eargs = {0}", arg)); } } }
Output:
C:\\ConsoleApplication1\ConsoleApplication1\bin\Debug>consoleapplication1 xx zz aa args.Length = 3 args = xx args = zz args = aa Eargs.Length = 4 Eargs = consoleapplication1 Eargs = xx Eargs = zz Eargs = aa
command-line c # visual-studio
mickeyf
source share