Solved

Initializing An Array Easily

Posted on 2006-10-20
3
271 Views
Last Modified: 2010-04-23
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)
0
Comment
Question by:GivenRandy
3 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
You simply have to iterate over the entire array and set each element...no way around it.
0
 
LVL 9

Expert Comment

by:Naveen Swamy
Comment Utility
iteration would help you in this
0
 
LVL 8

Expert Comment

by:fatalXception
Comment Utility
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?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now