Click here to Skip to main content
14,699,605 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i run my code i got this error "Index was outside the bounds of the array."
My code is

Console.WriteLine("hello, {0}!", args[0]);

Help me plzzzzzzzz
Posted

If you really do not understand the reason for that message then you need to read this book[^] as a starter.
   
Place a breakpoint on the above line of code, hover your mouse over args[0] and see if there are any values in the args array.

It appears that you're not passing in any command line arguments, hence the exception...
   
v2
You should first look at the args.Length for example and check if there are any arguments. You can also use the examples below to traverse all arguments.

In the main routine:

foreach(string arg in args)
{
   Console.WriteLine(arg);
}


Or outside the main routine:
foreach (string arg in Environment.GetCommandLineArgs())
{
    Console.WriteLine(arg);
}


Good luck!
   

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