制定平均计划

时间:2013-04-25 00:21:12

标签: c# user-interface average

我正在尝试制作一个程序,找到动态双打数的平均值,但我需要引用其他方法中的项目。

public int count = 0;
    public double[] nums = new double[1000];
    public Form1()
    {
        InitializeComponent();
        label3.Text = "";
    }

    public void button1_Click(object sender, EventArgs e)
    {
        count++;
        string mucho = textBox1.Text;
        nums[count] = Double.Parse(mucho);
        string countstr = Convert.ToString(count);
        label3.Text = countstr;
    }

    public void button2_Click(object sender, EventArgs e)
    {
        double average = 0;
        int count2 = 0;
        string countstr2 = label3.Text;
        int value = Convert.ToInt32(countstr2);
        while (count2 <= value)
        {
            count2++;
            average = +nums[count2];
        }
        double average2;
        average2 = average / count2;
        string ans = Convert.ToString(average2);
        label2.Text = ans;
    }

1 个答案:

答案 0 :(得分:0)

只需使用List或编写自己的平均函数

   private void button1_Click(object sender, EventArgs e)
    {
        List<double> dynDouble = new List<double>();

        // TODO Cast your array to a List<double>

        double result = dynDouble.Average();
    }