I have a class that looks something like this:
public class Parent
{
private string sFirst_name1;
public string sParent1FirstName
{
get { return sFirst_name1; }
set { sFirst_name1 = value; }
}
private string sLast_name1;
public string sParent1LastName
{
get { return sLast_name1; }
set { sLast_name1 = value; }
}
private List<int> lChild_ID;
public List<int> lChildID
{
get { return lChild_ID; }
set { lChild_ID = value; }
}
public Parent(string sP1FN, string sP1LN, List<int> lCID)
{
lChild_ID= new List<int>();
sFirst_name1 = sP1FN;
sLast_name1 = sP1LN;
lChild_ID = lCID;
}
I create an instance of the class and add it to a List of type Parent with the line:
lParents.Add(new Parent(sParent1FNTemp, sParent1LNTemp,lParentChildIDTemp));
Where lParentChildIDTemp is just a null integer List.
Later on, I am trying to update the int list of the object at a specified index by saying:
lParents[iIndex].lChildID.Add(++iIDCounters);
And I get a null reference exception. I'm not too sure why, but I think it has something to do with my constructor for my class. The weird thing is, I have another class that does pretty much the same thing but it doesn't throw the exception. If anyone has any clues, I would be greatful.