0

I am getting an error message when taking in command line arguments into an array. The error message states the index was outside the bounds of the array. I've never done this before and found an example online where this works.

This also works with local file paths but not UNC paths. I don't understand why what the string contains would cause an error like this. please help!

private static string[] _allFiles;
private static string _pickup;
private static string _dropOff;
private static int _size;
private static string _sizeInBytes;

static void Main(string[] args)
{
    _pickup = args[0];
    _dropOff = args[1];
    _sizeInBytes = args[2];

    SplitFiles();
}

Error is received at _dropOff = args[1];

System.IndexOutOfRangeException occurred HResult=0x80131508 Message=Index was outside the bounds of the array. Source= StackTrace:

14
  • 2
    This is because you didn't provide enough arguments to the program on the command line. How are you executing it? Commented Oct 16, 2017 at 18:14
  • please use a search engine the next time before asking. I knew the duplicate answer just a second after I read your error message... Commented Oct 16, 2017 at 18:14
  • make sure you give 3 arguments when you call the exe. eg : your_exe.exe pickup_val dropoff_val sizeinbytes Commented Oct 16, 2017 at 18:14
  • @mnistic I am providing it three arguments with spaces in between each one. Commented Oct 16, 2017 at 18:17
  • from what @cramopy posted above it makes it look like i didn't initialize my array but i didn't think that was something i needed to do when it is only being used inside of the method and then assigning to class variables. Commented Oct 16, 2017 at 18:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.