C#"}"错误:命名空间定义,预期文件结束

时间:2014-06-20 17:11:24

标签: c# namespaces

我不能为我的生活找到我失踪或额外的地方"}"是的,有新鲜眼睛的人可以指出我吗?!这是一个非常简单的错误,我似乎无法为自己弄清楚。此外,如果您发现其他可能有益于适合的错误,请告诉我,谢谢!

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

namespace NetchemiaWorksheet1
{

    private class Undergraduate 
    {

        // Initializing student information 
        private string StudentType;
        private string FirstName;
        private string LastName;
        private string Address;
        private long Phone;
        private long CafeteriaCredit;

        //Making private variables accesible
        private void SetString()
        {

            StudentType = "Undergraduate";
            FirstName = "Ian";
            LastName = "Lally";
            Address = "14512 S. Blackfoot Dr. Olathe, KS 66062";

        }

        public string GetString()
        {

            return StudentType;
            return FirstName;
            return LastName;
            return Address;

        }

        public void SetLong()
        {
            //Setting initial cafeteria credit to $0.00
            CafeteriaCredit =(long) 0.00;
            Phone = 9135155997;

        }

        public long GetLong()
        {

            return Phone;
            return CafeteriaCredit;

        }

    }

    private class Graduate
    {

        // Initializing student information
        private string StudentType;
        private string FirstName;
        private string LastName;
        private string Address;
        private long Phone;
        private long CafeteriaCredit;

        //Making private variables accesible
        private void SetString()
        {

            StudentType = "Graduate";
            FirstName = "Oscar";
            LastName = "Wilde";
            Address = "P. Sherman 42, Wallaby Way, Sydney Australia";

        }

        public string GetString()
        {

            return StudentType;
            return FirstName;
            return LastName;
            return Address;

        }

        public void SetLong()
        {

            CafeteriaCredit =(long) 0.00;
            Phone = 5557070707;

        }

        public long GetLong()
        {

            return Phone;
            return CafeteriaCredit;

        }

    }

    private class Doctorate
    {

        // Initializing student information
        private string StudentType;
        private string FirstName;
        private string LastName;
        private string Address;
        private long Phone;
        private long CafeteriaCredit;

        //Making private variables accesible
        private void SetString()
        {

            StudentType = "Doctorate";
            FirstName = "Albert";
            LastName = "Einstein";
            Address = "1600 Pennsylvania Ave NW, Washington, DC 20500";

        }

        public string GetString()
        {

            return StudentType;
            return FirstName;
            return LastName;
            return Address;

        }

        public void SetLong()
        {

            CafeteriaCredit =(long) 0.00;
            Phone = 5551234567;

        }

        public long GetLong()
        {

            return Phone;
            return CafeteriaCredit;

        }

    }  

class Program
    {

    static void Main(string[] args)
    {
        //initializing Classes
        Undergraduate IanLally = new Undergraduate();
        Graduate OscarWilde = new Graduate();
        Doctorate AlbertEinstein = new Doctorate();

        //Data members are inaccessible directly
        //Accessing through Methods within Class

        string U = IanLally.GetString();
        long UL = IanLally.GetLong();
        string G = OscarWilde.GetString();
        long GL = OscarWilde.GetLong();
        string D = AlbertEinstein.GetString();
        long DL = AlbertEinstein.GetLong();


            //Pulling Student Transcript
            public void Transcript(string StudentType) 
            {
                //Pseudo code
                Console.WriteLine("Retrieve" + StudentType + "Transcript");

            }

            //Enrolling in new course
            public void NewClass()
            {
                //Making array of classes available
                string[] Courses = new string[] {"ANTH 200", "BIOL 100", "PSYC 104", "ECON 144"};

                Console.WriteLine("Choose the courses in which you would like to enroll by entering the course acronym: ");

                //outputting Courses array
                foreach(var item in Courses) {

                    Console.WriteLine(item.ToString());

                }

                //Pseudo code
                    Console.WriteLine("Course" + Courses[1] + "added.");

            }

            //Buying lunch credits
            public void Credit() 
            {

                    //pseudo code
                Console.WriteLine("How much would you like to add to your Cafeteria Credits?");
                Console.WriteLine("Amount now added to your credits.");

            }
}
}
}

1 个答案:

答案 0 :(得分:3)

请看这个重复错误的小提琴:https://dotnetfiddle.net/eObBMs

编译器很困惑,因为它看到了一个方法定义,它需要一个结束括号。

问题是您缺少一个括号,但您在方法中定义了方法。你不能这样做。

static void Main(string[] args)方法中定义的方法拉出Main方法。