2
foreach(Unit enemy in enemies.OrderByDescending(enemy=>enemy.CurrentHP))
{
    Events.UnitDamaged(enemy);
    return;
}

如何将多个键值传递给排序?就像是

enemies.OrderByDescending(enemy => enemy.CurrentHP && enemy.MaximumHP)
4

3 回答 3

5

使用ThenBy

enemies.OrderByDescending(enemy => enemy.CurrentHP)
       .ThenBy(enemy => enemy.MaximumHP)

或者ThenByDescending

enemies.OrderByDescending(enemy => enemy.CurrentHP)
       .ThenByDescending(enemy => enemy.MaximumHP)
于 2013-09-10T11:44:49.137 回答
0

你可以做

enemies.OrderByDescending(enemy => enemy.CurrentHP)
       .ThenByDescending(enemy => enemy.MaximumHP)
于 2013-09-10T11:45:17.703 回答
0

试试这个:

enemies.OrderByDescending(enemy => enemy.CurrentHP)
       .ThenByDescending(enemy1 =>  enemy1.MaximumHP)
于 2013-09-10T11:45:20.283 回答