我正在尝试完成一项作业,但遇到以下问题(过去 12 小时我一直在做这件事)。请帮忙。
我打开了一个文件,将文件保存到一个结构数组中。可以访问结构的每个元素,但不知道如何访问每个单独的字段。IE
结构
//struct to hold the hand values
public struct CurrentHand
{
public char cardSuit;
public int cardValue;
}
我需要将其提取cardValue
到一个数组或变量中,以便我可以评估每条记录,即手是一对还是两对等。我不知道该怎么做。从我发现不可能访问每个字段,这是真的吗?
//Open file and load data into array
public static void LoadHandData(CurrentHand[] handData, string fileName)
{
string input = ""; //temporary variable to hold one line of data
string[] cardData; //temporary array to hold data split from input
//Open the file and read the contents
StreamReader readHand = new StreamReader(fileName);
input = readHand.ReadLine(); //one record
cardData = input.Split(' '); //split record into fields
for (int counter = 0; counter < handData.Length; counter++)
{
handData[counter].cardSuit = Convert.ToChar(cardData[counter *2]);
handData[counter].cardValue = Convert.ToInt16(cardData[counter *2 +1]);
}
readHand.Close();
}