根据多个键值对数组进行排序

时间:2021-10-11 21:46:28
foreach(Unit enemy in enemies.OrderByDescending(enemy=>enemy.CurrentHP))
{
    Events.UnitDamaged(enemy);
    return;
}

How to pass multiple key values to Sorting? Something like

如何将多个键值传递给排序?类似的

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

3 个解决方案

#1


5  

Use ThenBy:

使用ThenBy:

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

Or ThenByDescending:

或ThenByDescending:

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

#2


0  

Try this:

试试这个:

enemies.OrderByDescending(enemy => enemy.CurrentHP)
       .ThenByDescending(enemy1 =>  enemy1.MaximumHP)

#3


0  

You could do

你可以做

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

#1


5  

Use ThenBy:

使用ThenBy:

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

Or ThenByDescending:

或ThenByDescending:

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

#2


0  

Try this:

试试这个:

enemies.OrderByDescending(enemy => enemy.CurrentHP)
       .ThenByDescending(enemy1 =>  enemy1.MaximumHP)

#3


0  

You could do

你可以做

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