我的代码有两个问题:
1- 我在 Main() 中使用 Console.Writeline 时遇到奇怪的语法错误,我认为我缺少右花括号 '}'
2- 在 Main() 之后,我似乎无法弄清楚我的第一个方法。它应该是一个简单的 void 方法来编写数组的元素,但 Visual Studio 似乎认为它是错误中的类或命名空间。
谁能发现我哪里搞砸了?
public static void Main(string[] args)
{
//static array for winning[6], empty for player[6], empty for matching[6]
int [] winning = new int [6] {2, 4, 6, 9, 1, 3};
int [] player = new int [6];
int [] matching = new int [6];
int inValue;
//Input loop
Console.WriteLine("Please enter six lotto numbers, between 1 and 9");
for (int i = 0; i < player.Length; i++)
{
inValue = Console.Read();
if (inValue < 1 || inValue > 9) //Validate for int 1-9
{
Console.WriteLine("Please enter a whole number between 1 and 9");
}
winning[i] = inValue;
}
//Output
Console.WriteLine("The winning numbers were:");
DisplayArray(int[] winning);
Console.WriteLine("Your numbers were:");
DisplayArrayContents(int[] player);
Console.WriteLine("You had " + MatchCount() + " matches.");
Console.WriteLine("Your matching numbers are:")
DisplayArrayContents(int[] matching);
Console.Read();
}
//Empty method to display arrays
static void DisplayArray(params int[] args)
{
for (int i = 0; i < args.Length; i++)
{
Console.Write({0} + "\t", array[i]);
}
Console.Write("\n");
}
编辑:谢谢大家!我忘了重命名那里的一些变量和方法,但主要问题是缺少;和不必要的数据类型作为 Main() 中的参数。