Skip to content

Foreach loop

begin22

Asked Feb 12, 2006, 9:31 AM EST2 answers
Share
LinkedInX
double[] pArray= new double[50]; foreach (int i in problem7Array) { pArray[i]= i * 1.13; } how come i never get's incremented and stays at 0 for all 50 iterations? Steve

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Why do you want to use foreach in this case? I think you had better use for loop. Because i always get value for  your pArray instead of increment. In another hand, your pArray also doesn't have any value.
    0
  • 0
    interesting ;-)
    when you are using foreach,
    int i represents an item in the collection
    further more if it is a value type (like in your case int) it is read only

    foreach basically repeats a group of statements for each value in a collection

    Cheers!
    0