2015-10-15 52 views
1

所以基本上我已经声明了数组INT存在[,]的地方,但是当我尝试将值赋给它变成了形式加载,它说,它命名为“地方”并不在当前的背景下

不会在目前情况下

存在......我不能为我的生命找出原因。

int pbNum = 0; 
int stepFrame = 0; 
int stepLeft; 
int[,] place; 
public Form1() 
{ 
    InitializeComponent(); 

} 
private void Form1_Load(object sender, EventArgs e) 
{ 
    Player.Location = new Point(100,Ground.Top - 64); 
    SetStyle(ControlStyles.OptimizedDoubleBuffer, true); 
    foreach (var pb in this.Controls.OfType<PictureBox>()) 
    { 
     place(0, pbNum) = pb.Left; 
    pbNum += 1; 
    } 
    this.Text = pbNum.ToString(); 
} 
+1

1)你没有初始化该变量的函数,但阵列; 2)使用方括号:place [0,pbNum] = ... – JleruOHeP

+0

@ Tanruss1 [那你为什么要像使用方法一样使用数组?](https://msdn.microsoft.com/en-us/library /2yd9wwz4.aspx) – Prix

+0

@JleruOHeP谢谢,我还不太习惯c#,这是我第一次上课 – Tanruss1

回答

1

唯一的问题是。它不是

foreach (var pb in this.Controls.OfType<PictureBox>()) 
{ 
    place[0, pbNum] = pb.Left; 
    pbNum += 1; 
} 

我已经改变了()[]

相关问题