2
我怎么能忽略name属性空当排序依据如何才能忽略“空”的条款
student.Students= student.student.OrderBy(s=> s.Name ?? null).ToList();
上面的代码总是返回列表list of students having Name = null as 1st element
和student with name 'system' in the end.
我想ignore/exclude null in orderby
什么。 n个ull should always come to end of the the list
清洁,简单,流畅... +1 –
@Tim Schmelter谢谢,1:0代表第三行代码的含义是什么? – simbada
@simbada:它只是排序值,如果名称为空,则采用'1',如果不为空'0'则采用。由于0小于1,所以非空值先来。你也可以编写:'.OrderBy(s => s.Name == null)'。这将工作,因为结果是一个'布尔',其中'真'比'假'更“大”。 –