Csharp/C Sharp/Development Class/Command Line

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

illustrates how to read command-line arguments

<source lang="csharp"> /* Mastering Visual C# .NET by Jason Price, Mike Gunderloy Publisher: Sybex; ISBN: 0782129110

  • /

/*

 Example10_4.cs illustrates how to read
 command-line arguments
  • /

using System; public class Example10_4 {

 public static void Main(string[] arguments)
 {
   for (int counter = 0; counter < arguments.Length; counter++)
   {
     Console.WriteLine("arguments[" + counter + "] = " +
       arguments[counter]);
   }
 }

}

      </source>


Program argument input values: Converts degrees Celsius to degrees Fahrenheit

<source lang="csharp"> using System; public class PassArguments {

 public static void Main(String[] args) {
   double  hotC, coldC;
   double  hotF, coldF; 
   if (args.Length != 2) {
     Console.WriteLine ("Enter a hot and a cold temerature as program arguments.");
     return;
   }       
   hotC = double.Parse(args[0]); 
   hotF = 9.0*hotC/5.0 + 32.0;  
   Console.WriteLine ("The Fahrenheit temperature is: {0:F1}", hotF);
   coldC = double.Parse(args[1]); 
   coldF = 9.0*coldC/5.0 + 32.0;
   Console.WriteLine ("The Fahrenheit temperature is: {0:F1}", coldF);
 }

}

      </source>