Link to home
Start Free TrialLog in
Avatar of GivenRandy
GivenRandy

asked on

Initializing An Array Easily

Say I have something like this:

Public MyArray(100) As Single

Suppose I want to initialize all of them to 5.55. Is there an easy way?

Also consider the same for two-dimensional array:

Public MyArray(10,10) As Single

Edit: a way INSTEAD of using a For loop (or two For loops)
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Naveen Swamy
Naveen Swamy

iteration would help you in this
whilst you can write this:

public myarray() as single = new single() {10,14,12,34} which will create a 4 element array with the values 10,14,12,34, you cannot initialise a fixed sized array like this.  Its just not allowed.

But I suppose if you really want to avoid a loop you could write it as
public myarray() as single = new single() {5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5} ...don't bother counting them, I have no idea how many there are there :)

Is there some particular reason why you don't want to do a loop?