C# 出了点问题。”;错误CS1513:}应为“预期”;

C# 出了点问题。”;错误CS1513:}应为“预期”;,c#,C#,我是一个初学者 我写了一个程序,但无法编译,有一条错误消息: 错误CS1513:}应为空 我正在使用VisualStudio代码 请帮助我在以下代码行中查找问题 using System; namespace My_Program { internal class NewBaseType { static void Main(string[] args) { Console.WriteLine("Do you wa

我是一个初学者 我写了一个程序,但无法编译,有一条错误消息:

错误CS1513:}应为空

我正在使用VisualStudio代码 请帮助我在以下代码行中查找问题

using System;
namespace My_Program
{
    internal class NewBaseType
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Do you want to roll 1 or 2 dice");
            int dice = Convert.ToInt32(Console.ReadLine());

            // 1 dice
            if (dice == 1) {
                 Random numberGen = new Random();

            numberGen.Next(0, 6);
            int roll = 0;
            int attempts = 0;

            Console.WriteLine("Press enter to roll the die");
            Console.ReadLine();

            while (roll != 6) {
            roll = numberGen.Next(1, 7);
            Console.WriteLine("Your rolled: " + roll);
            attempts++;

            Console.WriteLine("It took you " + attempts + " attempts to get a six");
            }
            }

            //2 dice
            if (dice == 2) {
                     Random numberGen01 = new Random();
                     Random numberGen02 = new Random();

             numberGen01.Next(0, 6);
             numberGen02.Next(0, 6);
            
            int roll01 = 0;
            int attempts01 = 0;

            int roll02 = 0;
            int attempts02 = 0;

            Console.WriteLine("Press enter to roll the die");
            Console.ReadLine();

            while (roll01 != 6) {
            roll01 = numberGen01.Next(1, 7);
            Console.WriteLine("Your rolled: " + roll01);
            attempts01++;

            while (roll02 != 6) {
            roll02 = numberGen02.Next(1, 7);
            Console.WriteLine("Your rolled: " + roll02);
            attempts02++;

            int total = roll01 + roll02;

            Console.WriteLine("It took you " + total + " attempts to get a two sixes");
            }
            Console.ReadKey();
        }
    }
}

错误在最后一行(第66行),有人能帮我吗?

假设您使用的是visual studio;按CTRL+E,D将按照配置的约定重新格式化文档,这将使根本问题变得显而易见-大括号确实不平衡:

看起来您缺少了2个大括号,用于结束
命名空间
作用域。然而,代码逻辑本身也可能有一些奇怪之处,比如大括号

注意:重新格式化选项也可通过菜单-编辑->高级->格式化文档:


如果您以正确的方式缩进代码(或让编辑器缩进),则大括号将更容易配对。事实上,您需要使用更干净、更好的代码格式标准,而不必考虑将大括号放在何处。。。堆栈溢出不是为了询问缺少或冗余大括号的位置,抱歉。也就是说,my VS中的一个简单复制/粘贴显示,在提供的代码末尾缺少2个右大括号。仅此而已,只需添加
}
;大多数工具都会主动阻止您尝试这样缩进(或不缩进,视情况而定)。但是,在devenv(visualstudio)中:按“Ctrl+E,D”-hey presto,您的代码格式正确,错误显而易见。它可以像在末尾添加
}
一样简单(显然格式正确),但我无法推测大括号实际上应该放在哪里。