[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Initializing An Array Easily

Posted on 2006-10-20
3
Medium Priority
?
284 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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 17775518
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
ID: 17775932
iteration would help you in this
0
 
LVL 8

Expert Comment

by:fatalXception
ID: 17776548
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses
Course of the Month19 days, 20 hours left to enroll

872 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