代码没问题,一运行就报错。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Studengt studengt;
private void button1_Click(object sender, EventArgs e)
{
studengt = new Studengt();
studengt.Usename = textBox1.Text;
studengt.Yuwen = Convert.ToInt32(textBox2.Text);
studengt.Shuxue = Convert.ToInt32(textBox3.Text);
int zongfen =Convert.ToInt32(textBox1.Text) +Convert.ToInt32(textBox2.Text);
int pingjunfen =( Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text))/2;
Comm.list.Add(studengt);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
for (int i = 0; i < Comm.list.Count; i++)
{
ListViewItem list1 = new ListViewItem(Comm.list[i].Usename, i);
list1.SubItems.Add(Comm.list[i].Yuwen.ToString());
list1.SubItems.Add(Comm.list[i].Shuxue.ToString());
list1.SubItems.Add(Comm.list[zongfen].ToString());
listView1.Items.Add(list1);
}
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
}
}
//Studengt类
namespace 项目1
{
class Studengt
{
private string usename;
public string Usename
{
get { return usename; }
set { usename = value; }
}
private int yuwen;
public int Yuwen
{
get { return yuwen; }
set { yuwen = value; }
}
private int shuxue;
public int Shuxue
{
get { return shuxue; }
set { shuxue = value; }
}
}
}
//公用类Comm
namespace 项目1
{
class Comm
{
public static List<Studengt> list = new List<Studengt>();
}
}
[ 本帖最后由 yebanbaobei 于 2013-4-15 14:39 编辑 ]