[英]Sorting list alphabetically and by type
I have a list of instruments and I need to sort them to the following requirement. 我有一份仪器清单,我需要将它们分类为以下要求。
order by: 订购:
I have a list of instrument which has properties name and type, I've managed to sort alphabetically by name. 我有一个具有名称和类型属性的仪器列表,我设法按名称按字母顺序排序。
Instruments.Sort(Function(x, y) String.Compare(x.Name, y.Name))
Instruments.Sort((x, y) => string.Compare(x.Name, y.Name));
But I've been unable to come up with a graceful way of achieving the requirement. 但是我一直无法提出一种达到要求的优雅方法。
Appreciate any help. 感谢任何帮助。
Thank you. 谢谢。
If you're using .NET 3.5 you can use LINQ 如果您使用的是.NET 3.5,则可以使用LINQ
var sorted = Instruments
.OrderBy( x => x.Name )
.ThenBy( x => x.Type );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.