I am trying to make a array out of object of the class called "Logistics", but when I do it, I get a "System.NullReferenceException" error.
public class Generate_Logistic_List
{
Logistics[] logistic = new Logistics[2];
public void Generate()
{
logistic[0].ChangeName("Test");
}
}
What baffles me is that when I make it into a regular object of a class (i.e not making it an array) it works.
public class Generate_Logistic_List
{
Logistics logistic = new Logistics();
public void Generate()
{
logistic.ChangeName("Test");
}
}
Here is my "Logistics" class for reference.
public class Logistics
{
protected string name;
protected int time;
protected int manpower;
protected int ammo;
protected int rations;
protected int parts;
public string Name(){
return name;
}
public int Time(){
return time;
}
public int Manpower(){
return manpower;
}
public int Ammo(){
return ammo;
}
public int Rations(){
return rations;
}
public int Parts(){
return parts;
}
public int TotalSupplies(){
return manpower + ammo + rations + parts;
}
public double SupplyPerHour(int anySupply){
double x = time / 60;
return anySupply/x;
}
public void ChangeName(string newName){
name = newName;
}
public void ChangeTime(int newTime){
time=newTime;
}
public void ChangeSupplies(int newManpower, int newAmmo, int newRations, int newParts){
manpower=newManpower;
ammo=newAmmo;
rations=newRations;
parts=newParts;
}
}
I have looked around the googles and to me it seems like my syntax for making the class into an array is okay.
If there would be a problem with my "Logistics" class I would presumable get an error when making a single object out of the class.
When I searched googles regarding array of classes the results seems to be about different problems, but since a relatively new to this I might have missed it thinking it wasn't relevant.
If that is the case I would be happy if somebody could redirect me to the post. I actually have no idea where else I could search for the answers to my problem, so any help would be very much appreciated.