public void RemovePile() { int currentpileindex = Piles.IndexOf(CurrentPile); if (currentpileindex == Piles.Count - 1) { Piles.Remove(CurrentPile); if (currentpileindex == 0) { CurrentPile = null; } else { CurrentPile = Piles.Last(); } } else { Piles.Remove(CurrentPile); CurrentPile = Piles[currentpileindex]; } }