对两个或更多值排序通用列表 [英] Sort Generic list on two or more values

查看:181
本文介绍了对两个或更多值排序通用列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



产品类具有热门属性,数字(asc),点击数字(desc),名称字符串(asc)。为了命名属性,我们希望列表进行排序。



它如何用lamba语句排序?如果已经发现基于一个属性对列表进行排序。

VB的问题。这里是VB.Net解决方案

  Dim list = GetSomeList()
Dim sorted = list。 _
OrderBy(函数(x)x.Popular)。 _
ThenBy(Function(x)x.Clicked)。 _
ThenBy(Function(x)x.Name)

C#版本。尝试以下内容:

  var list = GetSomeList(); 
var sorted = list.OrderBy(x => x.Popular).ThenBy(x => x.Clicked).ThenBy(x => x.Name);


We have a generic List(Of Product) that must be sorted on two or more properties of the Product class.

The product class has the properties "Popular" numeric (asc), "Clicked" numeric (desc), "Name" string (asc). In order of naming the properties we want the list to sort.

How can it be sort with an lamba statement? If have found to sort the list based on one property.

解决方案

EDIT Just realized this was a VB question. Here is the VB.Net solution

Dim list = GetSomeList()
Dim sorted = list. _
  OrderBy(Function(x) x.Popular). _
  ThenBy(Function(x) x.Clicked). _
  ThenBy(Function(x) x.Name)

C# version. Try the following

var list = GetSomeList();
var sorted = list.OrderBy(x => x.Popular).ThenBy(x => x.Clicked).ThenBy(x => x.Name);

这篇关于对两个或更多值排序通用列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆