Sorting list alphabetically and by type
I have a list of instruments and I need to sort them to the following requirement.
order by:
- cash
- securities in alphabetical order
- managed funds in alphabetical order
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.Comp开发者_如何学运维are(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
var sorted = Instruments
.OrderBy( x => x.Name )
.ThenBy( x => x.Type );
精彩评论