gpt4 book ai didi

c# - 按多个键值对数组进行排序

转载 作者:行者123 更新时间:2023-12-02 04:51:45 25 4
gpt4 key购买 nike

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

如何将多个键值传递给排序?有点像

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

最佳答案

使用ThenBy :

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

ThenByDescending :

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

关于c# - 按多个键值对数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18718071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com