我该如何调试?列出的错误是:}预期。我有所有括号匹配 [英] How do I debug this? Listed error is: } expected. I have all brackets matching

查看:73
本文介绍了我该如何调试?列出的错误是:}预期。我有所有括号匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

namespace AssignmentModule3
{
    class Program
    {
        static void Main(string[] args)
        {
            static void GetStudentInformation()
            {
                Console.WriteLine("Enter the student's first name: ");
                string firstName = Console.ReadLine();
                Console.WriteLine("Enter the student's last name");
                string lastName = Console.ReadLine();
                Console.WriteLine("Enter the student's birthday: ");
                string birthDay = Console.ReadLine();
            }
        }
    }
}

推荐答案

你无法申报C#中另一个方法内的方法(除了匿名代表,但你会在几周内完成)



目前,你正在尝试创建你在Main方法体内的GetStudentInformation方法 - 所以在新方法声明之前,main的关闭花括号是缺失。

尝试:

You can't declare a method inside another method in C# (except for anonymous delegates, but you'll get to that in a couple of weeks)

At the moment, you are trying to create your GetStudentInformation method inside the body of the Main method - so the close curly bracket for main is "missing" before the new method declaration.
Try:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AssignmentModule3
{
    class Program
    {
        static void Main(string[] args)
        {
            GetStudentInformation();
        }
        static void GetStudentInformation()
        {
            Console.WriteLine("Enter the student's first name: ");
            string firstName = Console.ReadLine();
            Console.WriteLine("Enter the student's last name");
            string lastName = Console.ReadLine();
            Console.WriteLine("Enter the student's birthday: ");
            string birthDay = Console.ReadLine();
        }
    }
}


这篇关于我该如何调试?列出的错误是:}预期。我有所有括号匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆