2015-10-15 51 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; 
} 

我已經改變了()[]

相關問題