This is, what works for me

using System;

namespace PassArgsOnLinux
{
        class MainClass
        {
                public static void Main (string[] args)
                {
// not neccessary needed:
//                      string[] myArgs=null;
//                      int a=0;
//
//                      if (args!=null) {
//                              a = args.GetLength(0);
//                              myArgs = new string[a];
//                              for (int i = 0; i < a; i++) {
//                                      myArgs[i]=args[i];
//                              }
//                      }

                        Console.WriteLine ("Hello World!");
                        if (args!=null) {
                                Console.WriteLine ("You passed {0} args.", 
args.GetLength(0));
                                for (int i = 0; i < args.GetLength(0); i++) {
                                        Console.WriteLine("arg {0}: 
{1}",i+1,args[i]);
                                }
                        } else {
                                Console.WriteLine ("You passed 0 args.");
                        }

                        Console.ReadLine();
                }
        }
}

/********** Thats what my console says: *************
 *                                                                              
 *      $       mono PassArgsOnLinux.exe -myarg         
 *              Hello World!                                            
 *              You passed 1 args.                                      
 *              arg 1: -myarg                                           
 *                                                                              
 *      $       mono PassArgsOnLinux.exe                        
 *              Hello World!                                            
 *              You passed 0 args.                                      
 *                                                                              
 *      $       mono PassArgsOnLinux.exe -myarg1 -myarg2        
 *              Hello World!                                                    
 *              You passed 2 args.                                              
        
 *              arg 1: -myarg1arg 2: -myarg2                            
*************************************************/


--
View this message in context: 
http://mono.1490590.n4.nabble.com/How-to-run-program-with-arguments-tp3624788p3627639.html
Sent from the Mono - General mailing list archive at Nabble.com.
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to