开发者

Sorting list alphabetically and by type

I have a list of instruments and I need to sort them to the following requirement.

order by:

  1. cash
  2. securities in alphabetical order
  3. 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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜