我在窗体双击的相应中赋值了一个一维数组,我在其中一个按钮的响应中想调用这个数组 我该怎么办?
请大虾们帮忙

解决方案 »

  1.   

    参考:private int[] a = null;
    protected override void OnDoubleClick(EventArgs e)
    {
    base.OnDoubleClick(e);
    a=new int[]{1,2,3,6,8};
    }
    private void button1_Click(object sender, EventArgs e)
    {
    if (a != null)
    {
    Console.WriteLine(a.Length);
    }|
    }
      

  2.   

    这样也没有问题啊。一样可以访问啊。
    private int[] a = new int[5];
    protected override void OnDoubleClick(EventArgs e)
    {
        base.OnDoubleClick(e);
        for (int i = 0; i < a.Length; i++)
        {
            x[i] = i;
        }
    }
    private void button1_Click(object sender, EventArgs e)
    {
        if (a != null)
        {
            Console.WriteLine(a.Length);
        }
    }