传递变量double []

时间:2014-09-23 20:01:15

标签: c#

我有以下代码:

protected void btn1_Click(object sender, EventArgs e)
{
double[] value1 = {1010,2010,3010,4010,5010};
double[] value2 = {1020,2020,3020,4020,5020};
}
protected void btn2_Click(object sender, EventArgs e)
{
double begin = Math.Round(value1.Min() / 100d, 0) * 100;
double end = Math.Round(value1.Max() / 100d, 0) * 100;
//then some more math happens using value1 and value1
}

如何声明double []以便它可以在事件处理程序之间传递,所以基本上btn1_Click为value1和value2分配一些值,而btn2_click使用value1和value2进行某些计算

1 个答案:

答案 0 :(得分:2)

将两个double值(数组)声明为类中的变量应允许您在该类的代码中的任何位置使用它们。

class X
{
    double[] value1;
    double[] value2;

    protected void btn1_Click(object sender, EventArgs e)
    {
        double[] val1 = {...};
        value1 = val1;
        double[] val2 = {...};
        value2 = val2;
    }
}

等等。