Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Args-> IndexOutOfRangeException was unhandled

Status
Not open for further replies.

jr8rdt

IS-IT--Management
Feb 9, 2006
59
0
0
US
I am a newbie. when I run this program I get
"IndexOutOfRangeException was unhandled"

it points to this line
" System.Console.WriteLine(args[0]);"


can you help?


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{

System.Console.WriteLine(args[0]);

if (args[0] == "-help")
{
System.Console.WriteLine("you press help");
}
else if (args[0] == "-processor")
{
System.Console.WriteLine("you press processor");
}


}
}
}
 
The args array is empty, that is why you cannot even access the first element. Test if args contains anything (e.i. args.Length > 0). This also means you run the console app without passing any parameters.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top