I m trying to make a program in Visual C# that has my one created class, and at application launch it creates an array of my class object, and this array of my object can be used all over the program. So any function, or a control s event can access the array of objects and their member variables. I created my class as "public" but for some reason i get these errors upon build: "The name MyArrayObjectNameHere does not exist in the current context" When I try to access the objects member variables inside a load file dialog event in which I am trying to load data from a file into the member variables of the object array.
对象数组需要在特定位置声明和构造,以便在每个上下文中存在吗?如果是,请告诉我在哪里?
我目前在主函数中声明它,在form1运行之前。
我的班级定义在自己的.cs文件和程序命名空间中看起来像这样:
public class MyClass
{
public int MyInt1;
public int MyInt2;
}
我在表单加载之前,在主函数内部声明对象数组。
MyClass[] MyArrayObject;
MyArrayObject = new MyClass[50];
for (int i = 0; i < 50; i++)
{
MyArrayObject[i] = new MyClass();
}
提前感谢任何帮助。