private void UpdateStudentObj(CollegeStudent stu) { if (stu == null) { return; } stu.IsMale = rdoMale.Checked; stu.Name = txtName.Text; stu.ScoreForEntranceExamination = Convert.ToInt32(txtScore.Text); }
private void ShowStudentInfo(CollegeStudent obj) { if (obj == null) { return; } this.txtName.Text = obj.Name; this.txtScore.Text = Convert.ToString(obj.ScoreForEntranceExamination); this.rdoMale.Checked = obj.IsMale; this.rdoFemale.Checked = !obj.IsMale; }
//将CollegeStudent对象序列化到文件中 private void SerializeObj(string FileName, CollegeStudent stu) { //创建FileStream对象 using (FileStream writer = new FileStream(FileName, FileMode.Create)) { //创建格式化器对象 IFormatter formatter = new BinaryFormatter(); //格式化器对象使用FileStream对象序列化对象 formatter.Serialize(writer, stu); MessageBox.Show("对象成功保存到文件:" + FileName); } }
public frmMain() { InitializeComponent(); stu = new CollegeStudent(); this.ClearInputControls(); }