数组越界问题
排序问题,最后显示引索数组越界,怎么解决为什么会有这个问题
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
float[] a = new float[5];
float temp;
int i = 0;
int j = 0;
private void bu1_Click(object sender, EventArgs e)
{
a[i] = Convert.ToSingle(text1.Text);
lal.Text += a[i] + " ";
i++;
}
private void bu2_Click(object sender, EventArgs e)
{
for (i = 1; i <=4; i++)
{ for(j=i+1;j<=4;j++)
if(a[i]>a[j])
{
temp=a[j];
a[j]=a[i];
a[j]=temp;
}
lal2.Text = "\n 排序之后:";
for(i=0;i<=4;i++)
{
lal2.Text +=a[i];
}
}
}
}