473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Working with arrays

is there a better way to fill an array then this

a is a auto generated value, always different.
its meant to loop through until the array is full of values, will this work?

int i=0;
while(array[array.Length-1] == null)
{
array[i] = a;
i++;
}

Jul 21 '05 #1
9 1449
Thaynann <Th******@discussions.microsoft.com> wrote:
is there a better way to fill an array then this

a is a auto generated value, always different.
its meant to loop through until the array is full of values, will this work?

int i=0;
while(array[array.Length-1] == null)
{
array[i] = a;
i++;
}


Well, this would be nicer:

for (int i=0; i < array.Length; i++)
{
array[i] = a;
}

I don't think there's anything in the framework to fill an array
though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Thaynann,

In addition to John sometimes called even a little bit better,

\\\
foreach (arrayType a) in array
{
a = x;
}
///
Cor
Jul 21 '05 #3
Not really, this code does nothing, you are simply assigning a local
variable (a) over and over, the array remains unchanged.

--
Francisco Padron
www.chartfx.com
Jul 21 '05 #4
Actually, this code doesn't even compile, in a foreach the loop variable is
declared as Read-Only.

--
Francisco Padron
www.chartfx.com
Jul 21 '05 #5
> Not really, this code does nothing, you are simply assigning a local
variable (a) over and over, the array remains unchanged.

Yes as it is in the sample from Jon and Thaynmann the same, and what is
explained by Thanynmann.

Can you tell me your intentions with this message?

Cor
Jul 21 '05 #6
> Actually, this code doesn't even compile, in a foreach the loop variable
is declared as Read-Only.


In what program language?

Cor
Jul 21 '05 #7
> Yes as it is in the sample from Jon and Thaynmann the same, and what is
explained by Thanynmann. Can you tell me your intentions with this message?


Sorry, but the code you posted does not make sense, in any language I know
anyways (C#, VB.NET, C++, J#), you can go ahead and test it if you want, .

My intention was simply to save Thaynann some time. Sorry if you took it
personal but after all the purpose of this newsgroup is to save people some
time, if you think I'm wrong simply post a sample using your code that does
what Thaynann wanted.

Peace

--
Francisco Padron
www.chartfx.com
Jul 21 '05 #8

See this doc ...

http://msdn.microsoft.com/library/de...hstatement.asp

Microsoft advises against altering members while in a foreach, however as
long as the member variable is a 'Reference' you could get away with it.
Value types will be treated as read only.

Hope this helps -J

"Francisco Padron" wrote:
Yes as it is in the sample from Jon and Thaynmann the same, and what is
explained by Thanynmann.

Can you tell me your intentions with this message?


Sorry, but the code you posted does not make sense, in any language I know
anyways (C#, VB.NET, C++, J#), you can go ahead and test it if you want, .

My intention was simply to save Thaynann some time. Sorry if you took it
personal but after all the purpose of this newsgroup is to save people some
time, if you think I'm wrong simply post a sample using your code that does
what Thaynann wanted.

Peace

--
Francisco Padron
www.chartfx.com

Jul 21 '05 #9
Condo <Co***@discussions.microsoft.com> wrote:
See this doc ...

http://msdn.microsoft.com/library/de...ary/en-us/csre
f/html/vclrftheforeachstatement.asp

Microsoft advises against altering members while in a foreach, however as
long as the member variable is a 'Reference' you could get away with it.
Value types will be treated as read only.


Just to be accurate, the variable is treated as read-only whether it's
a reference type or a value type. Don't forget that the value of a
reference type variable isn't the object itself, it's the reference.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: michael nieuwenhuizen | last post by:
<newbie alert> i have 2 related arrays that i wanna sort at once. if i try: print_r($my_array1); array_multisort($my_array1, SORT_ASC, $my_array2, SORT_ASC); print_r($my_array1); both...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
5
by: Frederic Soustra | last post by:
Hi, I am trying to speed up some work I have to do with a 3D Matrix. If I am not mistaken, C is row major, hence the matrix A of size 2 x 2 x 2 would be stored like this in memory:...
2
by: Gerbus | last post by:
Hi there, I'm working in VC++ 2005 Express, and all I want is to have a dynamic multidimensional array of type Here's my code:
3
by: chrisjob012 | last post by:
hi guys... need some help....!! i am working on a form that looks like a calender....!!... in that form i have added a group box....!! during runtime 30 labels are inserted in it to look like a ...
5
by: =?ISO-8859-1?Q?Jonathan_Gro=DF?= | last post by:
Hi everybody, in the sample below my programm gives a "Bus error" on the marked line. I don't get it why that happens. I followed the instructions in the C-FAQ. #include <math.h> #include...
26
by: tesh.uk | last post by:
Hi Gurus, I have written the following code with the help of Ivor Horton's Beginning C : // Structures, Arrays of Structures. #include "stdafx.h" #include "stdio.h" #define MY_ARRAY 15
8
by: Safy | last post by:
Hello, i really need some help, im new to python so having a bit of trouble. i have two arrays which i successfully pulled out from some data. i want to search these arrays for 2 number and when...
1
by: Stephen.Schoenberger | last post by:
I am working with some images as byte arrays and am not sure nor can I figure out if as I am reading the image and saving smaller sub- images I am reading across and down the image or down and back...
20
by: cowboyrocks2009 | last post by:
Hi, I need help to automate my code to take data from input file. Also I need to create it as a function so that I can pass it to some other program. I am new to Java so having a bit limitation to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.