P
Paul
Hi I have a generic list with the type being an object and am trying to fill
the list. It works partially but keeps overwritting the previous values. I
have
the generic list of objects of type Links
public List<Links> linksStructFollowup= new List<Links> ();
instance of an object of type Links
public Links newstructRelatedFollowup = new Links();
Links is just a class containing an integer and two strings
public class Links
{
private int _CountLink;
private string _URLLink;
private string _DescriptionLink;
}
along with the constructor to allow outside access to data and a few methods.
I have a loop as shown
for (int i = 0; i < 3; i++)
{
newstructRelatedFollowup.CountLink = i;
linksStructFollowup.Add(newstructRelatedFollowup);
}
Although a new object is added to the list, the linksStructFollowup data
of the previous itteration gets over written so you end up with
linkStructFollowup[0].CountLink = 2
linkStructFollowup[1].CountLink = 2
linkStructFollowup[2].CountLink = 2
where it should be
linkStructFollowup[0].CountLink = 0
linkStructFollowup[1].CountLink = 1
linkStructFollowup[2].CountLink = 2
the list. It works partially but keeps overwritting the previous values. I
have
the generic list of objects of type Links
public List<Links> linksStructFollowup= new List<Links> ();
instance of an object of type Links
public Links newstructRelatedFollowup = new Links();
Links is just a class containing an integer and two strings
public class Links
{
private int _CountLink;
private string _URLLink;
private string _DescriptionLink;
}
along with the constructor to allow outside access to data and a few methods.
I have a loop as shown
for (int i = 0; i < 3; i++)
{
newstructRelatedFollowup.CountLink = i;
linksStructFollowup.Add(newstructRelatedFollowup);
}
Although a new object is added to the list, the linksStructFollowup data
of the previous itteration gets over written so you end up with
linkStructFollowup[0].CountLink = 2
linkStructFollowup[1].CountLink = 2
linkStructFollowup[2].CountLink = 2
where it should be
linkStructFollowup[0].CountLink = 0
linkStructFollowup[1].CountLink = 1
linkStructFollowup[2].CountLink = 2