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);
}}编译时报错,好像是关于枚举变量的可访问性问题。
求高手指教
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);
}}编译时报错,好像是关于枚举变量的可访问性问题。
求高手指教
解决方案 »
- 在MDI中,关闭子窗体后,会执行父窗体的什么事件?
- 如何将数据文件中的连续多个空格替换成1个空格
- 提关于xml的个小问题?
- 在vs2005中如何生成 注释web页
- 关于类的析构函数
- 老大,C#编程中如何获取与另一个进程关联的应用程序文件名呢?
- 高手进,如何在精简版xp操作系统上能正常运行我的.net程序
- TjSell.TP2(string, int)”: 并非所有的代码路径都返回值 C:\Inetpub\wwwroot\DGWebSite\App_Code\TjSell.cs
- datagrid中CHeckBox的实现
- 圣诞快乐!高分相送!
- 有在MVC里做过301转向的大师吗?请指教一下
- winform treeview控件
interest interests;你这里没有声明可访问性,所以默认是私有的你的构造函数
public student(string name, int id, interest interests)
里面有interest这个枚举。这里有个问题,你在外面new这个Student类时,你怎样传入interest 这个枚举(interest 私有的,外部不可访问)
所以提示 枚举变量的可访问性问题
这句
enum interest { basketball, swimming, singing, reading, drawing };
相当于
private enum interest { basketball, swimming, singing, reading, drawing };
这样一来,在类的外部将无法使用interest类型。而class student的构造函数中使用了一类型的参数。顶楼上:)
enum interest { basketball, swimming, singing, reading, drawing };
这句钱加 public