嗨,人們我是新手在C#世界,我有一個問題。我已經做了我的程序在Form_Load方法的數組,但我需要訪問陣列中的picture_box方法是這樣的:在C中訪問私有方法#
private void Form2_Load(object sender, EventArgs e)
{
//In this method we get a random array to set the images
int[] imgArray = new int[20];
Random aleatorio = new Random();
int num, contador = 0;
num = aleatorio.Next(1, 21);
imgArray[contador] = num;
contador++;
while (contador < 20)
{
num = aleatorio.Next(1, 21);
for (int i = 0; i <= contador; i++)
{
if (num == imgArray[i])
{
i = contador;
}
else
{
if (i + 1 == contador)
{
imgArray[contador] = num;
contador++;
i = contador;
}
}
}
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile(@"C:\Users\UserName\Desktop\MyMemoryGame\" + imgArray[0] + ".jpg");
}
但我只得到了錯誤:錯誤1名「imgArray」不存在於當前上下文中
導致錯誤的線是什麼? – trutheality 2011-06-05 06:59:41