-3

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

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;
    }
4

1 回答 1

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();
    }
于 2013-04-25T05:50:21.273 回答