I'm aware there is a similar question: What's the difference between struct and class in .NET?
but mine is more specific to my situation so I'd appreciate if I could get an answer. I have a class to represent some type and when I'm trying to set an array of this class values it spits null reference exception but when I use a struct it doesn't. I need to use a class due to another limitation how can I make this happen?
my c# code in a nutshell:
public class Person
{
public string name;
public string imageLocation;
public string location;
public Person()
{
name = "";
imageLocation= "";
location = "";
}
}
in another class in the same namespace:
int i = 0;
Person[] people = new people[applicablePeople];
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read() && i < applicablePeople)
{
people[i].name= dr["Name"].ToString();
people[i].imageLocation= dr["ImageLocation"].ToString();
people[i].location = dr["Location "].ToString();
i++;
}
}
thnx in advance