Still a beginner so please bare with them me on this. I would like the ability to add a number value to my property after the list distinguishes that there are duplicate values.
For example, two users have inputted into the system that they have the same employee ID of 001, the List allows them both to go in then applies a condition to check the list for any duplicates so in this case there would be. Now this conditional is true, add 1 to that property so the last employee now has employee ID of 002.
I believe LINQ will more than likely be involved in this process, but not to sure on how to go about this. I understand I will also have to update my List after performing this after to maintain the properties state throughout the program.
Thanks in advance hope everything is clear, question again How to add value to a property within a List<>
Code Snippet below.
Employee = new Employee(employeeFirstName, employeeLastName,001); // Hard coded for sake of example.
EmployeeList.AddEmployee(Employee);
EmployeeList Class
public static void AddEmployee(Employee employee)
{
employees.Add(new Employee(employee.FirstName,employee.LastName,employee.EmployeeID));
employees.Add(new Employee("John", "Jones", 001));
}
public void employeeIdValidation()
{
if (employees.Count() != employees.Select(x => new {staffId = x.EmployeeID }).Distinct().Count())
{
Console.WriteLine("Every Book and Category should be unique");
// employee ID increments by 1
// update List
}
else
{
Console.WriteLine("No duplicate found");
}
}
public static List<Employee> GetEmployeeList()
{
return employees; // With the updated EmployeeID
}