在排名列表与LT对象;>由多个条件 [英] Ranking objects in List<> by multiple criteria

查看:115
本文介绍了在排名列表与LT对象;>由多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代表植物对象的列表 - 每个都有代表一系列的可容忍的环境条件下的成员属性。

I have a list of objects representing plants - each of which have member properties which represent a range of tolerable environmental conditions.

我要重新排序此列表这样,该工厂对象以适宜的顺序排列。

I want to re-order this list such that the plant objects are ranked in order of suitability.

我想,我想给每个项目在列表中根据附近温度/ pH值适宜性等级它们的温度/ pH范围到所提供的环境数据的中间

I figure I want to give each item in the list a rank for temperature/pH suitability based on the proximity of the middle of their temperature/pH range to the environment data supplied.

我随后将平均行列和排序由该号码列表中。

I would then average the ranks and sort the list by this number.

不过,我不能确定,最好的办法是什么跟踪给列表中的每个项目的行列。 ?是否有人对如何最好地处理这个任何建议。

However, I'm unsure what the best approach would be for tracking the ranks given to each item in the list. Does anybody have any recommendations on how best to approach this?

推荐答案

您可以做到这一点是这样的:

You could do it like this:

var plants = new Plant[] { new Plant { T = 1, Ph = 2 },  new Plant { T = 2, Ph = 2 } };

var ps = from p in plants
         let magicNumber = p.T/p.Ph // Or some other algorithm
         orderby magicNumber
         select p;



然后,你可以创建任何您从植物的属性,如数量,你不具备实现比较器。

Then you can just create any number you like from the properties of a Plant and you don't have to implement a Comparer.

这篇关于在排名列表与LT对象;>由多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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