一个函数将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();
}
}
}