首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未知原因所期望的标识符c#

未知原因所期望的标识符c#
EN

Stack Overflow用户
提问于 2019-02-26 16:57:36
回答 2查看 305关注 0票数 0

试图制作一个简单的应用程序,它会问一些问题。但由于某种原因,我的AskQuestion函数无法工作。我计划在以后添加一个容易交换的数据库,这就是为什么我尝试采用一种稍微模块化的方法,而且由于我是初学者,我不知道自己做错了什么。唯一的错误是AskQuestion类的第21行。

错误是:

期望CS1001标识符 CS1514 {预期 CS1513 }预期

代码语言:javascript
复制
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.");
        }
    }
}
EN

回答 2

Stack Overflow用户

发布于 2019-02-26 16:59:48

改变这个

代码语言:javascript
复制
class void AskQuestion(Question Q)

代码语言:javascript
复制
void AskQuestion(Question Q)

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

票数 1
EN

Stack Overflow用户

发布于 2019-02-26 17:18:56

Q.givenanswer.ToLower();不使Q.givenanswer小写-它返回一个新的小写字符串,您需要分配给一个变量,或者只是`Q.givenanswer = Q.givenanswer.ToLower();

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54890547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档