0
我不确定我是否问这个正确的方法。如何应用类型类的索引?
我有这样的:
if (Winner[i] == LotteryArray[j][k])
{
Prediction++;
}
这是一个系列的循环内,基本检查从“中奖”行有多少个数字与LotteryArray
矩阵的每一行对应。但Winner
从本作:
static ShuffledRow WinningNums()
{
Console.WriteLine("Your winning numbers are!");
Console.WriteLine("------------------------");
ShuffledRow WinRow = new ShuffledRow(1, 46);
for (int i = 0; i < 6; i++) //this loop is to print the winning numbers
{
Console.Write("{0,3},", WinRow.Row[i]);
}
Console.WriteLine();
Console.WriteLine("------------------------"); //these two lines are for aesthetics
return WinRow;
这是从本作:
public class ShuffledRow
{
public static readonly Random Random = new Random();
public readonly int[] Row;
// Generates and shuffles some numbers
// from min to max-1
public ShuffledRow(int min, int max)
{
int count = max - min;
Row = Enumerable.Range(min, count).ToArray();
Shuffle(Row);
}
private static void Shuffle<T>(T[] array)
{
// shuffle
for (int i = array.Length - 1; i > 0; i--)
{
int j = Random.Next(i + 1);
T temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
现在,它告诉我,我不能申请用[]索引到类型的表达式ShuffledRow
我也试过这个:
if ((Winner<ShuffledRow[i]>) == LotteryArray[j][k])
{
Prediction++;
}
但它给我的问题无线出于某种原因括号。
这篇文章可能过长,但我不知道如果没有包括所有这些东西会有多混淆。
那么我该如何解决这个问题?
编辑:if (Winner.Row[i] == LotteryArray[j][k]) { Prediction++; }
这是它是如何应该是。谢谢范围H W
你尝试'ShuffledRow.Row [I] '? (ShuffledRow是你的自定义类 - 不是一个数组,你显然想访问的数组是该类内的成员变量Row) –
@HW like this((Winner)== LotteryArray [J] [K])'?因为这仍然给我括号的问题 –
Muffinator
如果你尝试这个,究竟是什么意思? –