using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class student
{
    string name;
    int id;
    enum interest { basketball, swimming, singing, reading, drawing };
    interest interests;    public student(string name, int id, interest interests)
    {
        this.name = name;
        this.id = id;
        this.interests = interests;
    }
    public student()
    {
        this.name = "ren";
        this.id = 09103414;
        this.interests = interest.basketball;
    }
    public override string ToString()
    {
        string data = string.Format("{0}{1}{2}", this.name, this.id, this.interests);
        return data;
    }
    public static void main()
    {
        student stu1 = new student();
        student stu2 = new student("Liang", 09103411, interest.reading);
        Console.WriteLine(stu1);
        Console.WriteLine(stu2);
    }}编译时报错,好像是关于枚举变量的可访问性问题。
求高手指教

解决方案 »

  1.   

    enum interest { basketball, swimming, singing, reading, drawing };
    interest interests;你这里没有声明可访问性,所以默认是私有的你的构造函数
    public student(string name, int id, interest interests)
    里面有interest这个枚举。这里有个问题,你在外面new这个Student类时,你怎样传入interest 这个枚举(interest  私有的,外部不可访问)
    所以提示 枚举变量的可访问性问题
      

  2.   

    对使用class声明的类型来说,没有使用访问说明符(public,private...)时默认为private,换句话说:
    这句
    enum interest { basketball, swimming, singing, reading, drawing };
    相当于
    private enum interest { basketball, swimming, singing, reading, drawing };
    这样一来,在类的外部将无法使用interest类型。而class student的构造函数中使用了一类型的参数。顶楼上:)
      

  3.   


    enum interest { basketball, swimming, singing, reading, drawing };
    这句钱加 public