public void CardbuttonClick(object sender, RoutedEventArgs e) { var b = (Button)sender; var c = new Card(b.Content.ToString()); for (var i = 0; i < amount; i++) { if (c.ToString() == Cards[i].ToString()) { correctCount++; leftCount = amount - correctCount; correctBlock.Text = correctCount.ToString(); leftBlock.Text = leftCount.ToString(); correctCards[correctCount - 1] = Cards[i]; Cards[i] = Card.Null(); return; } } wrongCount++; //wrongCardsCount++; //wrongCards[wrongCardsCount - 1] = Cards[amount - wrongCount]; for (var i = amount - 1; i >= 0; i--) { if (Cards[i].ToString() != "0") { wrongCards[wrongCardsCount++] = Cards[i]; Cards[i] = Card.Null(); wrongBlock.Text = wrongCount.ToString(); if (i > 0) { return; } } } for (var i = 0; i < amount; i++) { Cards[i] = wrongCards[i]; } wrongCards = Card.CardNullArray(amount); wrongCardsCount = 0; scoreCount++; scoreBlock.Text = scoreCount.ToString(); cardBox.Text = ""; foreach (var i in Cards) { cardBox.Text += i.ToString() + ' '; } }