Get command line arguments from Environment in CSharp

Description

The following code shows how to get command line arguments from Environment.

Example


//w ww  .  j  av  a 2 s.c om
  
     

  using System;
  using System.IO;

  class Class1 {
    static void Main(string[] args) {
      string [] cla  = Environment.GetCommandLineArgs();
      if (cla.GetUpperBound(0) == 2) {
        FileInfo fi = new FileInfo(cla[1]);
        fi.CopyTo(cla[2],true);
        Console.WriteLine("Copied " + fi.Length + " bytes.");
      }
      else{
        Console.WriteLine ("Usage: cp <input file> <output file>");
      }
    }
  }

The code above generates the following result.





















Home »
  C# Tutorial »
    Development »




Console
Encoding
Environment
Random