namespace 学生信息显示升级版
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//设置这些静态变量是为了充当全局变量
static int z=0;
static int a = 0;
static int b= 0;
static int c = 0;
public student[]st=new student[z];
static int i = 0;
static int two=a;
static int tree=c;
public class student
{
private string name;
private string sex;
private string banji;
private string jiguan;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public string Sex
{
get
{
return sex;
}
set
{
sex = value;
}
}
public string Banji
{
get
{
return banji;
}
set
{
banji = value;
}
}
public string Jiguan
{
get
{
return jiguan;
}
set
{
jiguan = value;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
label5.Text = "1班的学生人数是:"+textBox1.Text + "\n" + "2班的学生人数是:"+textBox2.Text + "\n" + "3班的学生人数是:"+textBox3.Text;
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = int.Parse(textBox3.Text);
z = a + b + c;
label10.Text = a + "\n" + b + "\n" + c + "\n" + z;//这句是为了检验a,b,c,z值有没有改变
} private void button2_Click(object sender, EventArgs e)
{
if (xuanzhe.SelectedIndex != -1)
{
tabs.SelectedTab = tab2;
if (xuanzhe.SelectedIndex == 0)
{
label6.Text = "1班人数为:" + a;
}
else
{
if (xuanzhe.SelectedIndex == 1)
{
label6.Text = "2班人数为:" + b;
}
else
{
label6.Text = "3班人数为:" + c;
}
}
}
else
{
MessageBox.Show("请选择第几班进行输入!");
} } private void label5_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
if (xuanzhe.SelectedIndex == 0)
{
student at1 = new student();
at1.Name = textBox4.Text;
at1.Sex = textBox5.Text;
at1.Jiguan = textBox6.Text;
if (i < a)
{
st[i++] = at1;//问题就在这里了,我一点录入就会显示索引超过数组界限
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox4.Focus();
}
else
{
MessageBox.Show("1班学生信息已全部输入完毕!");
}
}
else
{
if (xuanzhe.SelectedIndex == 1)
{
student at1 = new student();
at1.Name = textBox4.Text;
at1.Sex = textBox5.Text;
at1.Jiguan = textBox6.Text;
if (two < a + b)//问题就在这里了,我一点录入信息就会显示索引超过数组界限
{
st[two++] = at1;
}
else
{
MessageBox.Show("2班学生信息已全部输入完毕!");
}
}
else
{
student at1 = new student();
at1.Name = textBox4.Text;
at1.Sex = textBox5.Text;
at1.Jiguan = textBox6.Text;
if (tree < a + b + c)//问题就在这里了,我一点录入信息就会显示索引超过数组界限
{
st[two++] = at1;
}
else
{
MessageBox.Show("3班学生信息已全部输入完毕!");
}
} }
}
}
}
我是想弄一个信息显示程序,用选项卡弄了3页,首页先输入各班人数,然后用listview 选择要输入那班信息,然后就跳到第二页,进行输入,可是输入信息一想录入就会弹出索引 超过数组界限,不懂啊
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//设置这些静态变量是为了充当全局变量
static int z=0;
static int a = 0;
static int b= 0;
static int c = 0;
public student[]st=new student[z];
static int i = 0;
static int two=a;
static int tree=c;
public class student
{
private string name;
private string sex;
private string banji;
private string jiguan;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public string Sex
{
get
{
return sex;
}
set
{
sex = value;
}
}
public string Banji
{
get
{
return banji;
}
set
{
banji = value;
}
}
public string Jiguan
{
get
{
return jiguan;
}
set
{
jiguan = value;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
label5.Text = "1班的学生人数是:"+textBox1.Text + "\n" + "2班的学生人数是:"+textBox2.Text + "\n" + "3班的学生人数是:"+textBox3.Text;
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = int.Parse(textBox3.Text);
z = a + b + c;
label10.Text = a + "\n" + b + "\n" + c + "\n" + z;//这句是为了检验a,b,c,z值有没有改变
} private void button2_Click(object sender, EventArgs e)
{
if (xuanzhe.SelectedIndex != -1)
{
tabs.SelectedTab = tab2;
if (xuanzhe.SelectedIndex == 0)
{
label6.Text = "1班人数为:" + a;
}
else
{
if (xuanzhe.SelectedIndex == 1)
{
label6.Text = "2班人数为:" + b;
}
else
{
label6.Text = "3班人数为:" + c;
}
}
}
else
{
MessageBox.Show("请选择第几班进行输入!");
} } private void label5_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
if (xuanzhe.SelectedIndex == 0)
{
student at1 = new student();
at1.Name = textBox4.Text;
at1.Sex = textBox5.Text;
at1.Jiguan = textBox6.Text;
if (i < a)
{
st[i++] = at1;//问题就在这里了,我一点录入就会显示索引超过数组界限
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox4.Focus();
}
else
{
MessageBox.Show("1班学生信息已全部输入完毕!");
}
}
else
{
if (xuanzhe.SelectedIndex == 1)
{
student at1 = new student();
at1.Name = textBox4.Text;
at1.Sex = textBox5.Text;
at1.Jiguan = textBox6.Text;
if (two < a + b)//问题就在这里了,我一点录入信息就会显示索引超过数组界限
{
st[two++] = at1;
}
else
{
MessageBox.Show("2班学生信息已全部输入完毕!");
}
}
else
{
student at1 = new student();
at1.Name = textBox4.Text;
at1.Sex = textBox5.Text;
at1.Jiguan = textBox6.Text;
if (tree < a + b + c)//问题就在这里了,我一点录入信息就会显示索引超过数组界限
{
st[two++] = at1;
}
else
{
MessageBox.Show("3班学生信息已全部输入完毕!");
}
} }
}
}
}
我是想弄一个信息显示程序,用选项卡弄了3页,首页先输入各班人数,然后用listview 选择要输入那班信息,然后就跳到第二页,进行输入,可是输入信息一想录入就会弹出索引 超过数组界限,不懂啊
解决方案 »
- 如何去掉字符串中 最后一个数字之后的字符?
- 此功能如何实现
- 如何在静态方法中调用非静态方法
- 当我点击treeView激发它的BeforeSelect或者AfterSelect事件后,只能是点击鼠标左键才算选定了某对象,e才有意义,可是我想右键算呢?
- 如何正确配置ibitisnet框架。讲重点详细点 在线等
- 在 windows 2003 怎么才能知道本机安装 的 MDAC 版本?
- 一个复杂的问题,高手进
- 类中的提示信息
- 怎么打印RichTextBox中的内容?
- 求问C#怎么调用lame_enc.dll把wav转码成mp3?
- picturebox图片鼠标按下滚动条同步移动
- XmlElement LoadXml问题
if (tree < a + b + c)//问题就在这里了,我一点录入信息就会显示索引超过数组界限
{
st[two++] = at1;
}单步跟踪一下,有惊喜哦。
st=new student[z];
这样顺序写才对,不然ST[0]当然超过了.
if (two < a + b)//问题就在这里了,我一点录入信息就会显示索引超过数组界限
{
int index=two++ ;
if (index< st.Length)
{
st[index] = at1;
}
else
{
MessageBox.Show("数据值超过索引最大值!");
}
}