What's the best way to get the full path and filename of the invoked executable in c#?
<p>Given the following code:</p>

<pre><code>using System;

namespace Sandbox
{
   class CommandLine
   {
      static void Main()
      {
         String[] args = Environment.GetCommandLineArgs();
         String executable = args[0];
         String[] paramList = getParamList(args);

         System.Console.WriteLine("Directory ....... {0}", Environment.CurrentDirectory);
         System.Console.WriteLine("Executable ...... {0}", args[0]);
         System.Console.WriteLine("Params .......... {0}", String.Join(", ", paramList));
      }

      private static String[] getParamList(String[] args)
      {
         String[] paramList = new String[args.Length - 1];

         for (int i = 1; i &lt; args.Length; i++) 
         {
            int j = i - 1;
            paramList[j] = args[i];
         }

         return paramList;
      }
   }
}
</code></pre>

<p>... Saved as commandline.cs and <code>csc</code>’d to commandline.exe</p>

<p>I’d like to get the full path and filename of the execuatable being invoked. This code almost does it, however it’s not 100% accurate: </p>

<ul>
<li>if I call it as <code>commandline.exe foo bar baz</code> from the same directory; all is well</li>
<li>if I call it as <code>commandline foo bar baz</code> from the same directory, I only get the filename sans extension; not what I want</li>
<li>if I call it as <code>sandbox\commandline foo bar baz</code> from the parent directory; I get the relative path and partial filename</li>
</ul>

<p>I'm sure there's a much easier way of getting the full path and filename of the executable <em>other</em> than string manipulation, right?</p>
