gpt4 book ai didi

c# - 标识符应为 c# 未知原因

转载 作者:行者123 更新时间:2023-12-02 10:53:32 25 4
gpt4 key购买 nike

尝试制作一个简单的应用程序,它会问几个问题。
但由于某种原因,我的 AskQuestion 功能不起作用。
我计划稍后添加一个易于交换的数据库,这就是为什么我尝试采用更模块化的方法,因为我是初学者,我不确定我做错了什么。唯一的错误在 AskQuestion 类的第 21 行。
错误是:

CS1001 Identifier Expected

CS1514 { expected

CS1513 } expected

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.");
}
}
}

最佳答案

改变这个

class void AskQuestion(Question Q)


void AskQuestion(Question Q)

这应该是一种方法。关键字 class告诉编译器你想在 out 类中创建一个内部类 Program

关于c# - 标识符应为 c# 未知原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54890547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com