试图制作一个简单的应用程序,它会问一些问题。但由于某种原因,我的AskQuestion函数无法工作。我计划在以后添加一个容易交换的数据库,这就是为什么我尝试采用一种稍微模块化的方法,而且由于我是初学者,我不知道自己做错了什么。唯一的错误是AskQuestion类的第21行。
错误是:
期望CS1001标识符 CS1514 {预期 CS1513 }预期
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Quiz
{
class Program
{
// Question Base
class Question
{
public String question = "Empty Question";
public String correctanswer = "Empty Answer";
public String givenanswer = "Empty Answer";
public String response = "Empty Response.";
public bool cleared = false;
}
// Ask Base
class void AskQuestion(Question Q)
{
while (Q.cleared == false)
{
Console.WriteLine(Q.question);
Q.givenanswer = Console.ReadLine();
Q.givenanswer.ToLower();
if (Q.givenanswer == Q.correctanswer)
{
Console.WriteLine(Q.response);
Q.cleared = true;
}
else
{
Console.WriteLine("Wrong. Try again.");
}
}
}
// Main Function
void Main(string[] args)
{
string Name;
Console.WriteLine("Welcome challenger! You're going to have a good time.");
Console.WriteLine("Make sure you use proper grammar. Or you may be stuck for no reason.");
Console.WriteLine("What is your name challenger?");
Name = Console.ReadLine();
Console.WriteLine("Welcome {0} to the challenge. I wish you best of luck. You will need it.",Name);
Question Q1 = new Question();
Q1.question = "What is the color of the sun?";
Q1.correctanswer = "White";
Q1.response = "Correct. Despite the fact it appears Yellow on earth, if you observe the sun from space, you would see it's true color. White.";
AskQuestion(Q1);
Q1.cleared = true;
Console.WriteLine("Nice little warmup. But, lets get a bit serious.");
}
}
}发布于 2019-02-26 16:59:48
改变这个
class void AskQuestion(Question Q)至
void AskQuestion(Question Q)这应该是一种方法。关键字class告诉编译器要在out类Program中创建内部类。
发布于 2019-02-26 17:18:56
Q.givenanswer.ToLower();不使Q.givenanswer小写-它返回一个新的小写字符串,您需要分配给一个变量,或者只是`Q.givenanswer = Q.givenanswer.ToLower();
https://stackoverflow.com/questions/54890547
复制相似问题