Я не понимаю, почему эти два кода дают разные результаты
static string[] ranks = new string[13] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" }; public static int rankCounter = 0; public static string[] suits = new string[4] { "♠", "♣", "♦", "♥" }; public static int suitsCounter = 0; public static int shuffle; public static Random rnd = new Random(); public static int[] value = new int[52]; public static string numbers = string.Empty; public static string[] cards = new string[52]; static string[] ShuffleCardSystem() { string temp; for (int i = 0; i < 52; i++) { cards[i] = ranks[rankCounter] + suits[suitsCounter]; rankCounter++; if (rankCounter == 13) { rankCounter = 0; suitsCounter += 1; } } for (int i = 51; i >= 0; i--) { numbers = string.Empty; shuffle = rnd.Next(0, i); temp = cards[shuffle]; cards[shuffle] = cards[i]; cards[i] = temp; for (int position = 0; position < cards[i].Length; position++) { if (char.IsDigit(cards[i][position])) { numbers += cards[i][position]; value[i] = Convert.ToInt32(numbers]); if (value[i] == 1) { value[i] = 11; } } else if (cards[i].Any(char.IsLetter)) { value[i] = 10; numbers += cards[i][position]; } } } }
против этого...
static string[] ShuffleCardSystem() { string temp; for (int i = 0; i < 52; i++) { cards[i] = ranks[rankCounter] + suits[suitsCounter]; rankCounter++; if (rankCounter == 13) { rankCounter = 0; suitsCounter += 1; } } for (int i = 51; i >= 0; i--) { numbers = string.Empty; shuffle = rnd.Next(0, i); temp = cards[shuffle]; cards[shuffle] = cards[i]; cards[i] = temp; for (int position = 0; position < cards[i].Length; position++) { if (char.IsDigit(cards[i][position])) { static string[] ShuffleCardSystem() // WTF ? { string temp; for (int i = 0; i < 52; i++) { cards[i] = ranks[rankCounter] + suits[suitsCounter]; rankCounter++; if (rankCounter == 13) { rankCounter = 0; suitsCounter += 1; } } for (int i = 51; i >= 0; i--) { numbers = string.Empty; shuffle = rnd.Next(0, i); temp = cards[shuffle]; cards[shuffle] = cards[i]; cards[i] = temp; for (int position = 0; position < cards[i].Length; position++) { if (char.IsDigit(cards[i][position])) { value[i] = Convert.ToInt32(cards[i][position]); if (value[i] == 1) { value[i] = 11; } } else if (cards[i].Any(char.IsLetter)) { value[i] = 10; numbers += cards[i][position]; } } value[i] = Convert.ToInt32(numbers); if (value[i] == 1) { value[i] = 11; } } else if (cards[i].Any(char.IsLetter)) { value[i] = 10; } } } } } }
Наличие "чисел" не должно иметь значения, потому что оно равно [i][позиции]
Что я уже пробовал:
Я попытался очистить свои коды, но вместо того, чтобы показывать 1,2,3 в качестве значения, он дает 49,50,51, я просто хочу знать, почему