江南小生2004
幼苗
共回答了16个问题采纳率:93.8% 举报
方便计算我把 TextBox 换成了 NumericUpDown,自己改改就成了
Dictionary dict = new Dictionary();
dict.Add(0,numericUpDown1.Value);//0,0
dict.Add(1,numericUpDown2.Value);//0,1
dict.Add(2,numericUpDown3.Value);//0,2
dict.Add(3,numericUpDown4.Value);//0,3
dict.Add(4,numericUpDown5.Value);//1,0
dict.Add(5,numericUpDown6.Value);//1,1
dict.Add(6,numericUpDown7.Value);//1,2
dict.Add(7,numericUpDown8.Value);//1,3
dict.Add(8,numericUpDown9.Value);//2,0
dict.Add(9,numericUpDown10.Value);//2,1
dict.Add(10,numericUpDown11.Value);//2,2
dict.Add(11,numericUpDown12.Value);//2,3
dict.Add(12,numericUpDown13.Value);//3,0
dict.Add(13,numericUpDown14.Value);//3,1
dict.Add(14,numericUpDown15.Value);//3,2
dict.Add(15,numericUpDown16.Value);//3,3
decimal total = 0;
for (int i = 0; i < dict.Count; i++)
{
total += dict[i];
}
double avr = Convert.ToDouble(total / dict.Count);
label1.Text = string.Format("平均值为:{0}",avr);
Dictionary p = new Dictionary();
for (int i = 0; i < dict.Count; i++)
{
if ((double)dict[i] > avr)
{
p.Add(new Point(i / 4,i % 4),dict[i]);//高于平均值的位置及值(位置是唯一性,所以这里把它当做Key了,值有可能相同,所以不能用值来当做Key)
}
}
1年前
8