我的基本結構:如何將一個變量從一種方法傳遞給另一種方法?
public partial class _Search : BasePage
{
private string[] catPath = new string[3]; //set string array
...more code...
protected void Categories_DataBound(object sender, EventArgs e)
{
for (int i = 3; i > 0; i--)
{
catPath[i] = somestring; //fills array
}
}
...more code...
protected void Cat1_Click(object sender, EventArgs e)
{
MessageBox.Show(catPath[0]); //uses array
}
}
我在使用我的catPath
陣列中的Click
事件麻煩,就好像從來沒有在DataBound
方法設置是空的。我知道它是在Click
事件之前設置的,因爲我在DataBound
方法中使用了MessageBox
來顯示數組中的值,所以我做錯了什麼?
我試過類似的列表,但它有同樣的問題。像基本字符串的其他變量工作正常。
謝謝!
「其他變量,如基本字符串,雖然工作正常。」那麼哪種類型工作不正常呢? –
字符串數組 – MuffinMan