I am getting error :Index was outside the bounds of Array.”

Hi,

What I am trying to do: I am trying to create an dynamic array… However, when initiating the very first element of array I am getting the error :Index was outside the bounds of Array.

What I am doing:

Step 1: Created the Input Dialogue to accept the array size
Step 2: Assigning a count variable to 0
Step 3: Accepting element to enter into the array from user
Step 4: Checking if the count < array size entered by user in first step
Step 5: If condition on step 4 is true then assign the element to myArray(count)

On this step I am getting the error : “Index was outside the bounds of Array.”

Can anyone help please?

Dynamic arrays will be difficult to handle. So use lists instead

1 Like

I know… But I am a beginner and experimenting with basic stuff… Can you please help me with the error?

before using array you have to instantiate it as yourArray = new Array(Counter){}
Capture

1 Like

Thanks for your time as well as the solution @Madhavi

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.