# 通过多个键值对数组进行排序[英] Sorting array by multiple key values

### 问题描述

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

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

## 推荐答案

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

## 其他推荐答案

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

## 其他推荐答案

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

### 问题描述

```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)
```

## 推荐答案

Use ThenBy:

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

## 其他推荐答案

You could do

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

## 其他推荐答案

Try this:

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