Wednesday, 7 August 2013

Adding values to member fields of object in List at same index

Adding values to member fields of object in List at same index

I have a collection of type object called MHP. MHP has multiple member
fields(Name, AC, Par_ID, etc). I create a List;
private List<MHP> mhpList = new List<MHP>();
public List<MHP> MHPList
{ get { return mhpList; } set { mhpList = value; } }
And I populate a portion of the fields with values in a for loop by
creating a new object:
mhpList.Add(new MHP
{
MHP_Name = something,
MHP_AC = a number
});
Now I want to populate the remaining field with a value and I'm doing so
by creating a new object, but this obviously places the value in a new
index of the collection;
mhpList[0] MHP_Name = 'Something', MHP_AC = '#', MHP_ParId = null.
mhpList[1] MHP_Name = null, MHP_AC = null, MHP_ParID = 'something'
I've tried creating a new list and adding a new object to that list then
using the following to add the new list to mhpList:
mhpList.AddRange(newList)
as wellas and mhp.InsertRange, but each time this add a new index of the
object in the collection. How do I add values to unpopulated fields within
the SAME index of a collection?

No comments:

Post a Comment