Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Initializing An Array Easily

Posted on 2006-10-20
3
274 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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