小白一个,c#有一道题不会做
C#中在窗体上建立一个标签文本框一个按钮在列表框中列有3个同学的姓名,当选定某个学生姓名时,单击此按钮则在文本框中显示出该学生的班级
以下是我百度的例子,里面的 student类不用定义吗?如果要的话如何定义,直接百度的答案前头加下面这个吗?
public class student {
public student (string _name,string_class)
{
this.name=_name;
this.class=_class;}
public string name{get;set;}
public string class{get;set;}}
——————-下面是百度的——————
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.textBox1.Text = stu1[this.listBox1.SelectedIndex].classes;
}
student[] stu1=new student [3];
private void Form1_Load(object sender, EventArgs e)
{
stu1[0] = new student("s0", "c00");
stu1[1] = new student("s1", "c01");
stu1[2] = new student("s2", "c02");
for (int i = 0; i < stu1.Length; i++)
this.listBox1.Items.Add(stu1[i].name);
}
}