0

I have a list of employees which I get from database. I need to rearrange the list of employees to have fairness.

for example If I have List<Employee> employees = new List<Employee>();

while (reader.Read())
{
    departments.Add(new Department(Convert.ToInt16(reader.GetString("Did"))));
    departments[count].Name = reader.GetString("DName");
    departments[count].MinEarlyShift = Convert.ToInt16(reader.GetString("Minearlyshift"));
    departments[count].MinLateShift = Convert.ToInt16(reader.GetString("Minlateshift"));
    departments[count].EarlyShiftStart = Convert.ToDateTime( (reader.GetString("Earlyshift")));
}

now I have list of employees which will always have james in index 0 carter in index 1

but I want to rearrange this so carter may have the index 0 for example. basically shuffle the list.

abatishchev
  • 98,240
  • 88
  • 296
  • 433

1 Answers1

1
Random rnd = new Random();
var randomizedList = from empin allemployees 
                     orderby rnd.Next()
                     select emp;
Alireza
  • 10,237
  • 6
  • 43
  • 59