【发布时间】:2014-08-30 14:24:35
【问题描述】:
大家好,我需要在方法 Main 中使用方法 ValidateAns 中的 Int 调用点。我在网上搜索,人们说我应该做 ValidateAns(points),但它对我不起作用,我不确定我是否做错了,或者我应该使用其他方法来做
static void Main(string[] args)
{
const int QuestionNumbers = 10;
char[] Answear = new char[QuestionNumbers];
Question[] MCQ = new Question[QuestionNumbers];
MCQ[0] = new Question(Slaughterhouse);
MCQ[1] = new Question(Frankenstein);
MCQ[2] = new Question(Things);
MCQ[3] = new Question(Jane);
MCQ[4] = new Question(Kill);
MCQ[5] = new Question(Beloved);
MCQ[6] = new Question(Gatsby);
MCQ[7] = new Question(Catcher);
MCQ[8] = new Question(Pride);
MCQ[9] = new Question(Nineteen);
for (int i = 0; i < QuestionNumbers; i++)
{
Console.WriteLine("Question {0}", i + 1);
Answear[i] = MCQ[i]();
ValidateAns(i + 1, Answear[i]);
Console.WriteLine();
Console.ReadKey();
}
}
static void ValidateAns(int Nbr, char Ans)
{
int points= 0;
switch (Nbr)
{
case 1:
if (Ans == 'b' || Ans == 'B')
{
Console.WriteLine("Good Answear");
points++;
break;
}
else
{
Console.WriteLine("Wrong Answer - The right answer was (B)");
break;
}
}
}
【问题讨论】:
-
您可以从
ValidateAns返回bool以表明答案是否正确。在循环逻辑中,如果bool为真,您将向点数计数器加 1。 -
我认为这个问题不应该有标签[visual-studio-2012]!
标签: c# visual-studio-2012 methods integer