为什么会出现异常,要怎么解决这个问题? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
namespace WindowsApplication1 { public partial class caishu : Form { public caishu() { InitializeComponent(); } static int[] Num = new int[8];//猜数系列。 int i; private void button1_Click(object sender, EventArgs e) { Random m = new Random(); for ( i = 0; i < Num.Length; i++) { Num[i] = m.Next(100);
} foreach (int a in Num) {
for (int x = 0; x < i; x++) { if (Num[i] == Num[x]) { MessageBox.Show("运气很好!"); } else { MessageBox.Show("运气一般!"); } } textBox1.Text += a.ToString() + ","; }
}
} }
------解决方案-------------------- for (int x = 0; x < i; x++)//i是什么,改成Num.Length { if (Num[i] == Num[x]) {
------解决方案--------------------
------解决方案-------------------- for ( i = 0; i < Num.Length; i++)