一個函數將24個隨機字符串從具有for循環的數組輸入到字符串列表中。另一個函數顯示控制檯中列表中的字符串。然而,我只能得到一個值,例如111111111111111111111111111。當我設置斷點時,我得到了我正在尋找的輸出,如12kingace342356110。這是我的函數類代碼。C#輸出與斷點輸出不同
namespace CardWarConsoleGame
{
class Deck
{
public string[] CardNames = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
public int[] CardValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
}
class WarFunctions
{
public static List<string> YourDeck = new List<string>();
public static List<string> AIDeck = new List<string>();
public static void LoadCards()
{
Deck deck = new Deck();
for (int i = 0; i < 24; i++)
{
Random r = new Random();
YourDeck.Add(deck.CardNames[r.Next(0, 14)]);
}
}
public static void test()
{
for (int i = 0; i < YourDeck.Count; i++)
{
Console.Write(YourDeck[i]);
}
}
}
}
Heres the program.cs
namespace CardWarConsoleGame
{
class Program : WarFunctions
{
static void Main(string[] args)
{
LoadCards();
test();
Console.ReadLine();
}
}
}