对包含空值的列表进行排序
我一直在使用 C# 中的列表,我想知道如何轻松地对并不总是具有特定字段值的列表进行排序。
例如,如果有一个人员列表,每个人都有一个 DateOfBirth
,我想对所有人员进行排序,即使是那些没有该特定字段的人员,但我希望将它们分开来自原始组(有 DOB 的人)。
我知道这可能可以使用 LINQ 来完成,但我不太确定如何处理它。
任何帮助将不胜感激!
I have been working with lists in C# and I was wondering how to go about easily sorting a list that doesn't always have values for specific fields.
If, for instance, there was a list of people and each of them had a DateOfBirth
and I wanted to sort all of the people, even those without that specific field, but I would want those to be seperated from the original group (those with DOB).
I know that this could probably be done with LINQ but I am not really sure how to approach it.
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信这样的事情将实现您正在寻找的东西(使用 LINQ),或者可能为您指明正确的方向:
如果您正在寻找有关同一主题的其他信息,您可能需要查看以下文章:对空值列表进行排序 - Deborah Kurata
I believe something like this will accomplish what you are looking for (using LINQ), or perhaps point you in the right direction:
If you are looking for additional information on the same topic, you might want to check out the following article : Sorting Lists with Null Values - Deborah Kurata