大量无效令牌错误C#

时间:2016-11-27 00:57:24

标签: c# token

我是编码的新手,我正试图从一些问题开始讨厌。它一直很好,直到我到底,它给了我一些关于无效令牌的错误。请阅读这些内容并告诉我什么是错的

using System;

namespace CheckIfOver18
{
    class MainClass
    {
        public static void Main(string[] args)
        {
        Start:
            Console.WriteLine("How old are you? \n");
            int age = Convert.ToInt32(Console.ReadLine());
            int yes = y;
            if (age < 18)
            {
                Console.WriteLine("This game contains dismemberment and violence between victional characters, please get your parents or guardians to answer the next question.");
            }
            Console.WriteLine("\n This game contains dismemberment and violence between victional characters, do you allow your child to play this game? Please type y for yes or n for no");
            Console.ReadKey(yes);
            Console.WriteLine("Thank you for letting your child play this game, <press any key to continue");
            Console.ReadKey();
        }
            else Console.WriteLine ("Sorry your child is not able to play this game");
        goto Start;
            if (age > 18){
                Console.WriteLine("<Press any key to continue");
                Console.ReadKey();
        }
    }
}

我很新,所以如果你能告诉我怎么做直接的话会很好

1 个答案:

答案 0 :(得分:1)

这部分

else Console.WriteLine ("Sorry your child is not able to play this game");
    goto Start; //maybe without this line
        if (age > 18){
            Console.WriteLine("<Press any key to continue");
            Console.ReadKey();
    }

不应该是现在的位置,因为else以上的一行是Main方法的结束括号所以此代码在它之外且不能存在。可能应该在检查年龄的第一个条件之后&lt; 18.

yes = y也存在问题,并将yes传递给Console.ReadKey,但不接受任何参数。

您可以轻松地重写此代码以摆脱goto,因为在这种简单的情况下不需要它。