Error with adding a value to an array

Hey you all,

I have a question related to an error for adding a string to an array. I have the following:

Assign
axArray (array of strings)={}

Assign
axArray(0)=“Hello”

And get the following error:
Assign: Index was outside the bounds of the array.

But it’s an empty array and I index it at 0. So, how could it be outside the bounds?

@10uss You need to define the Size of the Array when you’re Initialising it. If you know the Maximum size the array will contain you can use this :

axArray = new String(10){}

then you can do this :

axArray(0)=“Hello”

2 Likes

@supermanPunch Okay, thank you for your answer, it is clear now! Than I have to look for a different method because in this way it’s not very dynamic (you first have to define the lenght of your array).

1 Like

@10uss, I suggest you to use List instead of array. Array is good for predefined length, List is good otherwise.

Cheers :slight_smile:

2 Likes

@Bhavik_Solanki thank you for the extra information! I Indeed switched to a list instead of an array.

1 Like

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