using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication1
{
class Student
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int age;
public int Age
{
get { return age; }
set
{
if (value > 18 && value < 25)
{
age = value;
}
else
{
age = 18;
}
}
}
private string major;
public string Major
{
get { return major; }
set { major = value; }
}
private string birth;
public string Birth
{
get { return birth; }
set {birth = value; }
}
private string sex;
public string Sex
{
get { return sex; }
set { sex = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 增加ToolStripMenuItem_Click(object sender, EventArgs e)
{
Student SS = new Student();
if (radioButton1.Checked == true)
{
SS.Sex = "男";
}
if (radioButton2.Checked == true)
{
SS.Sex = "女";
}
SS.Name = textBox1.Text;
SS.Age = int.Parse(this.textBox2.Text);
SS.Major = textBox3.Text;
SS.Birth = textBox4.Text;
listBox1.Items.Add(" 姓名:" + SS.Name + " 性别:" + SS.Sex + " 年龄:" + SS.Age + " 专业:" + SS.Major + " 籍贯:" + SS.Birth);
}
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.listBox1.Items.Remove(listBox1.SelectedItem);
}
}
}