Maha

Maha

  • NA
  • 0
  • 328.3k

foreach insted of for

Dec 10 2011 1:37 PM
I wish to whether it is possible to modify this program by using foreach instead for loop

using System;
public class ParallelArrays
{
public static void Main()
{
int[] validValues = { 101, 108, 201, 213, 266, 304, 311, 409, 411, 412 };

double[] prices = { 0.89, 1.23, 3.50, 0.69, 5.79, 3.19, 0.99, 0.89, 1.26, 8.00 };

//parallel array

int itemOrdered = 311;

for (int i = 0; i < validValues.Length; ++i)
{
if (itemOrdered == validValues[i]) //order doesn't matter
{
Console.WriteLine(prices[i]);
}
}
Console.ReadKey();
}
}
/*
0.99
*/


Answers (4)