There is nothing wrong, but is there any other nicea nicer way to re-write this program?
public IEnumerable<Employee> InsertEmployee(dynamic employees)
{
var newEmployeeRecord = new List<Employee>();
foreach (dynamic employee in employees)
{
newEmployeeRecord.Add(
new Employee
{
EmployeeId = Convert.ToInt32(employee.EmployeeId)
,
EmployeeName = Convert.ToString(employee.EmployeeName)
,
Age = Convert.ToInt32(employee.Age)
,
Salary = Convert.ToInt32(employee.Salary)
,
DepartmentId = Convert.ToInt32(employee.DepartmentId)
}
);
}
return EmployeeRecords.Concat(newEmployeeRecord);
}
Also, can we avoid typecasting? (I think it's not possible, so it could require an extension method.)