首页上一页 1 下一页尾页 1 条记录 1/1页
关于索引
发表在C#图书答疑
2009-10-08
是否精华
是
否
版块置顶:
是
否
public class student
{
public string name;
public int tel;
}
public class book
{
public student[] students;
public void initialize()
{
students = new student[3];
students[0] = new student();
students[0].name = "张三";
students [0].tel=25252;
students[1] = new student();
students[1].name = "李四";
students[1].tel = 572957;
}
public int this[string thename]
{
get
{
if (students[0].name == thename)
{
return students[0].tel;
}
else
{
return students[1].tel;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
book bk = new book();
this.richTextBox1.Text = bk["张三"].ToString();
}
}
运行错误:指向students[0].name == thename,未将对象应用设置到对象的实例
请问该怎么解决啊?
{
public string name;
public int tel;
}
public class book
{
public student[] students;
public void initialize()
{
students = new student[3];
students[0] = new student();
students[0].name = "张三";
students [0].tel=25252;
students[1] = new student();
students[1].name = "李四";
students[1].tel = 572957;
}
public int this[string thename]
{
get
{
if (students[0].name == thename)
{
return students[0].tel;
}
else
{
return students[1].tel;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
book bk = new book();
this.richTextBox1.Text = bk["张三"].ToString();
}
}
运行错误:指向students[0].name == thename,未将对象应用设置到对象的实例
请问该怎么解决啊?