foreach(Unit enemy in enemies.OrderByDescending(enemy=>enemy.CurrentHP))
{
Events.UnitDamaged(enemy);
return;
}
如何将多个键值传递给排序? 像
这样的东西enemies.OrderByDescending(enemy => enemy.CurrentHP && enemy.MaximumHP)
答案 0 :(得分:5)
使用ThenBy
:
enemies.OrderByDescending(enemy => enemy.CurrentHP)
.ThenBy(enemy => enemy.MaximumHP)
enemies.OrderByDescending(enemy => enemy.CurrentHP)
.ThenByDescending(enemy => enemy.MaximumHP)
答案 1 :(得分:0)
你可以做到
enemies.OrderByDescending(enemy => enemy.CurrentHP)
.ThenByDescending(enemy => enemy.MaximumHP)
答案 2 :(得分:0)
试试这个:
enemies.OrderByDescending(enemy => enemy.CurrentHP)
.ThenByDescending(enemy1 => enemy1.MaximumHP)