Return different value to the operating system based on the argument length

   
 

using System;
class SayHello {
    public static int Main(string[] args) {
        if (args.Length > 0) {
            foreach (string arg in args) {
                if (arg.Equals("/help")) {
                    Console.WriteLine("Run this program as follows:" +
                              "sayhello.exe [name1] ");
                    return (1);
                } else
                    Console.WriteLine("Hello " + "{0}", arg);
            }
            return (0);
        } else
            Console.WriteLine("For help, run sayhello.exe /help");
        return (2);
    }
}

    


Using command-line arguments to initialize an array.

using System;

public class InitArray
{
public static void Main( string[] args )
{
int arrayLength = Convert.ToInt32( args[ 0 ] );
int[] array = new int[ arrayLength ]; // create array

int initialValue = Convert.ToInt32( args[ 1 ] );
int increment = Convert.ToInt32( args[ 2 ] );

for ( int counter = 0; counter < array.Length; counter++ ) array[ counter ] = initialValue + increment * counter; Console.WriteLine( "{0}{1,8}", "Index", "Value" ); for ( int counter = 0; counter < array.Length; counter++ ) Console.WriteLine( "{0,5}{1,8}", counter, array[ counter ] ); } } [/csharp]