Apologies for what is probably a dumb question, but I think I've boiled my code down the the core issues, of which there are two that are driving me nuts. I'd appreciate any assistance.
In the code below, the first issue is when my debug gets to the line 'bus[0]..' I get the 'Object reference not set to an instance of an object', even though I just instantiated the class in the previous line.
My next issue is that the 'SystemArrays' class is intended to be a repository, visible by all my classes (such as 'Solver'), where they can Get & Set its public properties. However, I can't figure how or where to instantiate the class to make it visible to everyone.
Any help would be greatly appreciated. Thanks.
public Form1()
{
InitializeComponent();
}
SystemArrays newArray = new SystemArrays();
private void button1_Click(object sender, EventArgs e)
{
Bus[] bus = new Bus[3];
bus[0].elementNum = 5;
bus[1].elementNum = 8;
bus[2].elementNum = 26;
newArray.buses[0].elementNum = bus[0].elementNum;
}
public class SystemArrays
{
public Bus[] buses { get; set; }
}
public class Bus
{
public int elementNum { get; set; }
}
public class Solver
{
// int x = newArray.buses[0].elementNum;
}