C# 类型或命名空间定义,或应为文件结尾,且应为}

C# 类型或命名空间定义,或应为文件结尾,且应为},c#,C#,获取类型或命名空间定义,或预期的文件结尾和}。 我试着在网上查找这个问题,但没有变得更聪明 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _2_2_digital_vackarklocka { class Program { static void Main(

获取类型或命名空间定义,或预期的文件结尾和}。 我试着在网上查找这个问题,但没有变得更聪明

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2_2_digital_vackarklocka
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.BackgroundColor = ConsoleColor.DarkGreen;
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(" ╔══════════════════════════════════════╗ ");
            Console.WriteLine(" ║           Väckarklockan              ║ ");
            Console.WriteLine(" ╚══════════════════════════════════════╝ ");
            Console.ResetColor();
            Console.WriteLine();


            AlarmClock time = new AlarmClock(13, 24, 7, 35);

            Console.WriteLine(time);      // Tells me that } is expected


            static void Run(AlarmClock ac, int minutes)
            {

            }

        }
    }
}    // Type or namespace definition, or end-of-file expected

将Run方法移到Main方法之外。

您正在另一个方法中声明一个方法,这是不可能的。给它一个属于自己的地方:

namespace _2_2_digital_vackarklocka
{
    public class Program
    {
        static void Main(string[] args)
        {

                Console.BackgroundColor = ConsoleColor.DarkGreen;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(" ╔══════════════════════════════════════╗ ");
                Console.WriteLine(" ║           Väckarklockan              ║ ");
                Console.WriteLine(" ╚══════════════════════════════════════╝ ");
                Console.ResetColor();
                Console.WriteLine();


                AlarmClock time = new AlarmClock(13, 24, 7, 35);

                Console.WriteLine(time);
                // Tells me that } is expected
                // True, there should be one here to close the Main method
        }


        static void Run(AlarmClock ac, int minutes)
        {

        }
    }
}

你在另一辆车里开了一辆车。将该函数置于main之外。下一个

 static void Run(AlarmClock ac, int minutes)
            {

            }

这将解决错误。

Run方法应该被删除,不要试图在另一个方法中声明一个方法。在这种情况下,错误消息可能会更有帮助,但它是一条一般性的消息,表示给出的文本没有意义………啊,谢谢xD