Ok... I'm trying to understand this whole object oriented programming but I keep ending up in a dead end. ;)
I'm trying to store or rather will store a great deal of data with using classes as I should. I want to store planetary data by using a class with several properties, I will then save these into a list.
My problem is that I don't know how to make this list globally accessible, it is only accessible in the instance where it is created.
Some sample code from my test environment below.
OrbitalBodies.cs
class OrbitalBodies
{
public int BodyID { get; set; }
public string BodyName { get; set; }
public int BodySize { get; set; }
public int BodyX { get; set; }
public int BodyY { get; set; }
}
From1.cs
public void button1_Click(object sender, EventArgs e)
{
var bodies0 = new OrbitalBodies();
var orbitalList = new List<OrbitalBodies>();
bodies0.BodyID = 4;
bodies0.BodyName = "Earth";
bodies0.BodySize = 125;
bodies0.BodyX = -450;
bodies0.BodyY = 75;
orbitalList.Add(bodies0);
bodies0.BodyID = 0;
bodies0.BodyName = "Sol";
bodies0.BodySize = 500;
bodies0.BodyX = 0;
bodies0.BodyY = 0;
orbitalList.Add(bodies0);
//var orbitalDic = new Dictionary<int, OrbitalBodies>();
MessageBox.Show("Planetary body name: " + Convert.ToString(orbitalList.Count()));
}
I have spent a couple of hours looking up my problem here and other places but I don't know how I can access the information I put into the list other than in that single instance. My real application will have tens of thousands of orbital bodies and many other data that must be accessible throughout many forms and perhaps even other classes.
Some help would be appreciated, what is the best solution? Do it completely differently?!?