我有一个从数据库中获取的员工列表。我需要重新安排员工名单以保持公平。
例如,如果我有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")));
}
现在我有一份员工名单,这些员工在索引1的索引0卡特中总是有詹姆斯
但我想重新安排这个,所以卡特可能会有索引0。基本上洗牌了。
答案 0 :(得分:1)
Random rnd = new Random();
var randomizedList = from empin allemployees
orderby rnd.Next()
select emp;