The default value for any reference type is null
. So I assume you're getting a NullReferenceException
when you try to add values. You can initialize your list property to an empty list in the object's constructor:
public class RootObject
{
public List inchistory { get; set; }
public RootObject()
{
inchistory = new List();
}
}
Now any instance of RootObject
will have a valid (empty) list by default, allowing you to add to it:
Rootobject robj = new Rootobject();
robj.inchistor.Add(someInstanceOfInchistory);