Using Parellel Arrays in C#

Parallel arrays are two arrays that hold related values for a record in two separate arrays usign the element index to tie in the values.  For example, you can have an array of Wrestler and another array called Points.  The first array may be a string array with the values of

(Wrestler[0] = “Alexander Vasiliyevich”, Wrestler[1] = “Oscar Ilyich”) 

In integer-array, Points[0], you may have the value of 9 and 11 (i.e. Points[0] = 9, Points[1] = 11).  So if you wanted to reference the points Alexander had, you would output the values in both array using the same index, [0].  

 

using System;

using System.Collections.Generic;

using System.Text;

 

    class Program

    {

        static void Main(string[] args)

        {

            string[] Wrestler = new string[5]{"Alexander", "Oscar", "Ilya", "Pyotr", "Anton"};

            int[] points = new int[5]{9, 11, 9, 4, 12};

            int[] penaltyPoints = new int[5]{ 0, 0, 5, 2, 0 };

            string msgOut = "The following classes are accepting x number of students: \n \n";

            int count = 0;

            double r;

 

            foreach(string s in Wrestler)

            {

                r = Convert.ToDouble(points[count]) - Convert.ToDouble(penaltyPoints[count]);

               

                msgOut += s + " scored " + r + " net points \n";

                count++;

            }

 

            Console.Write(msgOut);

            Console.ReadLine();

        }

    }