Mega Code Archive

 
Categories / C# / Language Basics
 

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);     } }