日期:2014-05-17  浏览次数:20985 次

函数如何调用其它函数的局部变量?
在一个函数中产生的随机数数组,但是其他几个函数都想用这个数组,请问怎么调用?
比如:

private void ChooseToOverTurn(int count)
        {
            Random ran = new Random();
            int[] chooseIndex = new int[count];

            for (int i = 0; i < count; i++)
            {
                chooseIndex[i] = ran.Next(0, (count - 1) * (count - 1));
            }

            Image imgWhite = new Bitmap("images/white.png");
            foreach (Control c in this.panelMain.Controls)
            {
                if (c.GetType() == typeof(PictureBox))
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (c.Text == chooseIndex[i].ToString())
                        {
                            PictureBox p = c as PictureBox;
                            p.Image = imgWhite;
                        }
                    }
                }
            }
        }

        private void TurnBack()
        {
            Image imgBlack = new Bitmap("images/black.png");
            System.Threading.Thread.Sleep(1000);    //1000ms Wait for turnback
            foreach (Control c in this.panelMain.Controls)
            {