private void SortByInitiative() { for (int i = 0; i < Combatants.Count - 1; i++) { var highestIndex = i; for (int j = i + 1; j < Combatants.Count; j++) { if (Combatants[j].Initiative > Combatants[highestIndex].Initiative) { highestIndex = j; } else if (Combatants[j].Initiative == Combatants[highestIndex].Initiative) { if (Combatants[j].InitiativeBonus > Combatants[highestIndex].InitiativeBonus) { highestIndex = j; } } } if (i != highestIndex) { Combatants = (ObservableCollection <DD4ECombatant>)Combatants.Swap(i, highestIndex); } } }