0

I have an array with size[5]. I added 5 values into this array and then removed the values. Now my array have only one value. If I add another value to this array it shows the error Index was outside the bounds of the array.

Rahman
  • 330
  • 1
  • 7
  • 24
Sijiya
  • 1
  • 1
  • 3
  • 9
    Questions concerning problems with code you've written must describe the specific problem and *include valid code to reproduce it* in the question itself. – Sergey Berezovskiy Jan 06 '14 at 07:46
  • 3
    we love to see code, so if you don't mind please show it to us. – Ehsan Jan 06 '14 at 07:47
  • 2
    Adding and removing from the array? I suspect this is not an array. – Theraot Jan 06 '14 at 07:49
  • Funny that a post about this was just created today. [Check it out](http://stackoverflow.com/questions/20940979/what-is-indexoutofrangeexception-and-how-do-i-fix-it) – crthompson Jan 06 '14 at 07:51
  • 2
    Adding and removing are not the terms used with arrays. Might be you are assigning values to some array index and setting empty values for removal. no one can help you unless you share some code. – Shaikh Farooque Jan 06 '14 at 07:54
  • can you update your question with code you have written ? – SpiderCode Jan 06 '14 at 08:30

1 Answers1

1

If you have an array of size 5 you can add values 0 to 4 (arrays start at index 0):

object[] arr = new object[5];
arr[0] = new object();
arr[4] = new object();

// this will give your Index was outside the bounds of the array exception:
arr[5] = new object();
Peter
  • 27,590
  • 8
  • 64
  • 84