C# 运行到一般错误预期类、委托、枚举、接口或结构以及can';I don’我不知道我错在哪里

C# 运行到一般错误预期类、委托、枚举、接口或结构以及can';I don’我不知道我错在哪里,c#,methods,filestream,C#,Methods,Filestream,下面是两个方法,第一个错误是我需要一个},如下所示 我知道这通常意味着我在某个地方缺少一个括号,但我不认为是这样的,我也找不到任何错误的地方 public Customer(string first, string last) { FileStream getID = new FileStream(FILENAME, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);

下面是两个方法,第一个错误是我需要一个},如下所示

我知道这通常意味着我在某个地方缺少一个括号,但我不认为是这样的,我也找不到任何错误的地方

    public Customer(string first, string last)
    {
        FileStream getID = new FileStream(FILENAME, FileMode.OpenOrCreate,         FileAccess.Read, FileShare.ReadWrite);
        String line;
        string[] fields;
        try
        {
            //Pass the file path and file name to the StreamReader constructor
            StreamReader srID = new StreamReader(getID);

            //Read the first line of text
            line = srID.ReadLine();
            while(line != null)
              {
                 fields = line.Split(DELIM);
                 if (Convert.ToInt32(fields[2]) > CustomerID)
                    {
                        CustomerID = Convert.ToInt32(fields[2]);
                    }
                 line = srID.ReadLine();
              }

            //close the file
            srID.Close();
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }

        FileStream customerWrite = new FileStream(FILENAME, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
        int idCounter;

        try
        {

            //Pass the filepath and filename to the StreamWriter Constructor
            StreamWriter sw = new StreamWriter(customerWrite);

            //Write a line of text
            FirstName = first;
            LastName = last;
            CustomerID += 1;
            sw.WriteLine(ToString());

            //Close the file
            sw.Close(); 
        }
        catch(Exception e)
        {
            // messagebox
            MessageBox.Show(e.Message,"Problem",MessageBoxButtons.OK, MessageBoxIcon.Error);
            //Console.WriteLine("Exception: " + e.Message);
        } // asking for a } here

        public new string ToString()
        {
           return (FirstName + ',' + LastName + ',' + CustomerID);
        }
    }

    // checks for duplicate customer info
    public bool CustomerOrderCheck(string first, string last) // gives the expected class... for the bool here
    // pass the first and last name to be checked in the system for a previous entry
    {
        FileStream customerCheck = new FileStream(FILENAME, FileMode.OpenCreate, FileAccess.Read, FileShare.ReadWrite);
        String line;
        string[] fields;
        bool customerExists = false;
        try
        {
            //Pass the file path and file name to the StreamReader constructor
            StreamReader sr = new StreamReader(customerCheck);

            //Read the first line of text
            line = sr.ReadLine();
            while (line != null)
            {
                fields = recordIn.Split(DELIM);
                FirstName = fields[0];
                LastName = fields[1];
                if (FirstName + LastName == first + last) //(line.Equals(orderCheck))
                {
                    MessageBox.Show("This order has already been submitted, please try again","Order already exists",MessageBoxIcon.Warning);
                    //Console.WriteLine("This order has already been submitted, please try again");
                    customerExists = true;
                    break;
                }
                line = sr.ReadLine();
            }

            //close the file
            sr.Close();
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }
        return customerExists;
    }
}
我认为:

        } // asking for a } here

        public new string ToString()
        {
           return (FirstName + ',' + LastName + ',' + CustomerID);
        }
    }
应该是:

        }// asking for a } here
    }

    public new string ToString()
    {
        return (FirstName + ',' + LastName + ',' + CustomerID);
    }

函数中包含了一个函数。将ToString()函数移到Customer()函数之外。
只需在需要的地方加一个括号,并删除ToString()函数后的括号。

这似乎是它所要求的,但这意味着这是类的结尾,但它不是类的结尾,它只是该方法的结尾。对,ToString方法在它上面的方法中。