Here I'm trying to get the data for many employees that i predefined a class for it as This
public class Employee
{
public int code;
public float salary;
public float bonus;
public float deduction;
}
and i'm trying to make a function to create the array for the Employees and to ask the user to fill it
That's the code for now
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Task3
{
class Program
{
static void Main(string[] args)
{
int size = 3;
Employee[] E1 = GetEmployeeData(size);
}
static Colors GetIntFromUser(string Message)
{
int result;
Console.Write(Message);
result = int.Parse(Console.ReadLine());
Colors c = (Colors)result;
return c;
}
static Employee[] GetEmployeeData(int size)
{
for (int i = 0; i < size; i++)
{
Employee[] E = new Employee [size];
E[i] = new Employee();
Console.Write("Code: ");
E[i].code = int.Parse(Console.ReadLine());
Console.Write("Salary: ");
E[i].salary = float.Parse(Console.ReadLine());
Console.Write("Bonus: ");
E[i].bonus = float.Parse(Console.ReadLine());
Console.Write("Deduction: ");
E[i].deduction = float.Parse(Console.ReadLine());
return E[i];
}
}
}
}
i get that Error Severity Code Description Project File Line Suppression State Error CS0161 'Program.GetEmployeeData(int)': not all code paths return a value Task3 E:\ITI39\Intro to programming\tasks\day5\ConsoleApplication1\Task3\Program.cs 26 Active
and This one too Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type 'Task3.Employee' to 'Task3.Employee[]' Task3 E:\ITI39\Intro to programming\tasks\day5\ConsoleApplication1\Task3\Program.cs 40 Active
P.S. I don't Have Any OOP Experience more further i'm beginner in Programming
GetEmployeeDatamethod doesn't make much sense. You are creating an array inside theforloop (meaning you create a new one on each iteration) and also trying to return a single instance withreturn E[i];(also inside theforloop, meaning you would only ever have a single iteration if this compiled)return E;