您的位置:首页 > 新闻 > 热点要闻 > 南县网站开发_web服务器安装与配置_让手机变流畅的软件下载_商丘优化公司

南县网站开发_web服务器安装与配置_让手机变流畅的软件下载_商丘优化公司

2025/6/2 2:46:38 来源:https://blog.csdn.net/qq_44809934/article/details/146417288  浏览:    关键词:南县网站开发_web服务器安装与配置_让手机变流畅的软件下载_商丘优化公司
南县网站开发_web服务器安装与配置_让手机变流畅的软件下载_商丘优化公司

C#

升序排序

OrderBy

按升序对序列的元素进行排序

ThenBy

按升序对序列中的元素执行后续排序

降序排序

OrderByDescending

按降序对序列的元素排序

ThenByDescending

按降序对序列中的元素执行后续排序

public class Fruit
{public int id;public string name;public float price;public float weight;
}List<Fruit> list = new List<Fruit>();
list.Add(new Fruit { id = 2, name = "苹果", price = 9.9f ,weight = 500});
list.Add(new Fruit { id = 5, name = "西瓜", price = 1.2f, weight = 5000 });
list.Add(new Fruit { id = 1, name = "草莓", price = 29.9f, weight = 80 });
list.Add(new Fruit { id = 3, name = "香蕉", price = 6f, weight = 800 });
list.Add(new Fruit { id = 4, name = "哈密瓜", price = 2.5f, weight = 3000 });

升序排序

IOrderedEnumerable<Fruit> result = list.OrderBy(x => x.id).ThenBy(x=>x.price).ThenBy(x=>x.weight);

降序排序

IOrderedEnumerable<Fruit> result = list.OrderByDescending(x => x.id).ThenByDescending(x=>x.price).ThenByDescending(x=>x.weight);

Lua

local list = {[1] = {id = 101,name = "小明",age = 16,score = 88};[2] = {id = 103,name = "小红",age = 15,score = 91};[3] = {id = 107,name = "小刚",age = 16,score = 81};[4] = {id = 105,name = "小丽",age = 15,score = 91};[5] = {id = 104,name = "小龙",age = 14,score = 88};
}table.sort(list,function(a,b)if a.score == b.score thenif a.age == b.age thenreturn a.id > b.idelsereturn a.age > b.ageend  elsereturn a.score > b.scoreend  end)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com