Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning a decimal value to an individual employee c#

Tags:

string

c#

decimal

Im currently making a payroll system. I have like 5 or 6 employee's and each of them has a different hourly rate, how would I assign an hourly rate to each individual?!

At the moment I have something along the lines of(Which is incorrect)...

string[] employeeID = {"Brian", "Richard", etc....};
decimal hourlyPay = 0.0M;

if (employeeID == "Brian")
{
  hourlyPay = 8.00M;
}

Thanks!

like image 824
TheBiz Avatar asked Dec 03 '25 11:12

TheBiz


1 Answers

Try this code:

string[] employeeID = {"Brian", "Richard"};
decimal hourlyPay = 0.0M;
for (int i = 0; i < employeeID.Length; i++)
{
    if (employeeID[i] == "Brian")
    {
        hourlyPay = 8.00M;
    }

}
Console.WriteLine(hourlyPay);

Always use a loop to go through all elements in array, and access them by index. When populating, modifying elements, always use a loop.

like image 111
Eugen Sunic Avatar answered Dec 05 '25 00:12

Eugen Sunic