I need to sort in my studentsWatHighestDebts variable of type var (List) from students only those objects that matter in s.ZachetDidNotPass maximum or (maximum -1) in all List students
var StudentsWitHighestDebts = students .Where(s => s.ZachetDidNotPass.(some condition)) .OrderBy(s => s.Name) .ToList(); Suppose I have List students with objects that have a ZachetDidNotPass value of 0, 1, 2, 5, 6, 7 I need to put in the StudentsWitHighestDebts only those who have these values maximum or maximum -1. Ie those with 7 and 6
Help please. Itself with the help of MSDN could not figure it out ... Can it be solved like this:
foreach (var n in students) { if (n.ZachetDidNotPass > maxZachDidNotPass) { maxZachDidNotPass = n.ZachetDidNotPass; } if (n.ExamDidNotPass > maxExamDidNotPass) { maxExamDidNotPass = n.ExamDidNotPass; } } var StudentsWitHighestDebts = students .Where(s => s.ZachetDidNotPass == maxZachDidNotPass || s.ZachetDidNotPass == maxZachDidNotPass - 1 && s.ExamDidNotPass == maxExamDidNotPass || s.ExamDidNotPass == maxExamDidNotPass-1) .OrderBy(s => s.Name) .ToList();