lundi 1 juin 2015

Order a list by a field then by random

var r = new Random();
var orderedList = aListOfPeople.OrderBy(x => x.Age).ThenBy(x => r.Next());

What would be a better way of ordering a list by "age" and then by random?

My goal is to make sure that if PersonA age = PersonB age, PersonA will come first on some occasions and PersonB will come first on some other occasions.




Aucun commentaire:

Enregistrer un commentaire