C# 学生管理系统 - 添加、显示学生信息
namespace 管理系统
{
public partial class Form1 : Form
{
private List
private void button1_Click(object sender, EventArgs e)
{
string name = label1.Text;
string age = label2.Text;
string grade = label3.Text;
Student newStudent = new Student(name, age, grade);
students.Add(newStudent);
UpdateStudentList();
ClearInputFields();
}
private void UpdateStudentList()
{
listBox1.Items.Clear();
foreach (Student student in students)
{
listBox1.Items.Add(student);
}
}
private void ClearInputFields()
{
label1.Text = "";
label2.Text = "";
label3.Text = "";
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label1.Text = "";
label2.Text = "";
label3.Text = "";
}
public class Student
{
public string Name { get; set; }
public int Age { get; set; }
public string Grade { get; set; }
public Student(string name, string age, string grade)
{
Name = name;
Age = int.Parse(age);
Grade = grade;
}
public override string ToString()
{
return Name + ' ' + Age + ' ' + Grade;
}
}
}
}
原文地址: https://www.cveoy.top/t/topic/fMvJ 著作权归作者所有。请勿转载和采集!