在表單上建立一個串列框,一個文本框和一個按鈕,在串列框中列有十二個學生的姓名都選定某個學生姓名。單擊此按鈕,則在文本框上顯示出該學生的班級。
uj5u.com熱心網友回復:
下面的是我在度娘上找的答案,看不懂
student[] stu1=new student [3];這個定義的student類就直接這樣寫可以了嗎?不需要什么鋪墊嗎??
還有name和class不需要定義嗎?看不懂,新手自學問題多多哎
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);
}
}
單獨定義類,以三個學生為例
uj5u.com熱心網友回復:
下面的是我在度娘上找的答案,看不懂
student[] stu1=new student [3];這個定義的student類就直接這樣寫可以了嗎?不需要什么鋪墊嗎??
還有name和class不需要定義嗎?看不懂,新手自學問題多多哎
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);
}
}
單獨定義類,以三個學生為例
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/205025.html
標籤:其他開發語言
