class Class2
{
public string ven;
public List<string> lname = new List<string>();
}
List<Class2> l = new List<Class2>();
List<string> lhs = new List<string>();
Class2 c2 = new Class2();
c2.ven = line_split[0];
c2.lname = lhs;
l.Add(c2);
lhs.Clear();
When lhs.Clear() is executed , it empty out object l.
What is my alternative?
If you don’t want clearing
lhsto clear the list stored on an object, you have to copy the list when assigning it to your object’s field:Ideally you’d be doing this in
Class2‘s constructor.