Scott Abbott

Scott Abbott

  • NA
  • 1
  • 717

How do I save information into an array in c#?

Mar 30 2015 3:30 AM
I am in a very, very basic class. Essentially I wanted to use a function -- one that returns the double data type for each iteration of my for loop. I was able to accomplish this using a method (since arrays are already passed by reference into a method), but I was curious, could I accomplish the same thing using a function?


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter8_Prob_8
{
    class Program
    {
        const int MAX_SIZE = 7;
        static void Main(string[] args)
        {
            double[] empId = new double[MAX_SIZE] { 56588, 45201, 78951, 87775, 84512, 13028, 75804 };
            //the book calls for an integer array to hold the number of hours worked by each employee
            //this is unrealistic to use an integer, I need more points of accuracy. I will use a double.
            double[] hours = new double[MAX_SIZE];
            double[] payRate = new double[MAX_SIZE];
            double[] wages = new double[MAX_SIZE];

            //function to get the hours of the employees
            getHoursAndPay(empId, hours, payRate);
            calcWages(hours, payRate, wages);
            displayResults(empId, hours, payRate, wages);
        }//end main


Instead of using calcWages(hours, payRate, wages);
 would it be possible to have something like,
wages = calcWages(hours, payRate) and then have a function that would return
each 'wage' into each element of the array?

Answers (1)