How i can ignore Null in name property when orderby
student.Students= student.student.OrderBy(s=> s.Name ?? null).ToList();
The above code always return list of students having Name = null as 1st element in the list and student with name 'system' in the end.
What i want to ignore/exclude null in orderby. the null should always come to end of the the list
You can make a conditional OrderBy:
student.Students= student.student
.OrderBy(s=> s.Name == null ? 1 : 0)
.ThenBy(s => s.Name)
.ToList();
This splits first into two groups, the items with s.Name != null and those with s.Name == null. The second sort-condition is the Name itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With