Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am create one application that is working in console and ui.both r run using cmd commends only.in defaut ie is take console mode.when given commend like C:\Raju\selectedpath\bin\Release>selectedpath.exe tis is on commend prompt. and give path like C:\Raj\selectedpath\bin\Release>selectedpath.exe ui. this is open ui and run.this working good.but i am writ this one C:\Raju\selectedpath\bin\Release>selectedpath.exe then given error Index was outside the bounds of the array. I am write code below also please solve this problem
Code :
C#
[STAThread]
       static void Main(string [] args)
       {

               if (args[0] == "ui")
               {
                   Application.Run(new selectedpath.Form1());
               }
               else
               {
                   Console.WriteLine("dfdd");
               }

}
}
}
Posted

Well, args[] is an array conating all the arguments. How many arguments does it contain when you do call your application without arguments?
So check for the Length of the array first, before you try to access its first member.
 
Share this answer
 
Comments
CPallini 29-Nov-13 5:17am    
5.
Yes as per Bernhard said in solution 1, Check your array length before accessing its first index value.
Try the following

C#
if(args.length() > 0)
{	    
  if (args[0] == "ui")
    {
      Application.Run(new selectedpath.Form1());
    }
   else
    {
      Console.WriteLine("dfdd");
    }
}


Regards,
BlueSathish
 
Share this answer
 
Comments
CPallini 29-Nov-13 5:18am    
5.
bluesathish 29-Nov-13 5:22am    
Thank you so much. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900