我想要一个在两种不同方法之间共享的对象数组。
我网页上 button1 的 onclick 调用方法 1,它填充 objectArray 所需的值。我需要 button2 的 onclick 方法能够使用与 method1 正在处理的相同数据访问相同的 objectArray。
using myWebReference;
{
public partial class _Default : System.Web.UI.Page
{
ObjectArray[] myObjects = new ObjectArray[100];
public void Page_Load(object sender, EventArgs e)
{
//I have nothing in here at the moment
}
public void method1(object sender, EventArgs e)
{
//myObjects[]'s values are calculated and assigned here.
}
public void method2(object sender, EventArgs e)
{
String key = myObjects[0].value;
//when I try to get data within myObjects here, myObjects does exist,
//but it is empty and I get a null reference error when I try to use its values.
}
}