I’d like to use nested lists in my data acquistion application to store my incoming 16bit data dynamically. I created a list of UInt16 and added it three times (NUMCHANNEL=3) to a List type list. Now I expect that I can add an Uint16 entry the way the code shows below:
public List<UInt16> TBATT16 = new List<UInt16>();
public List<List<UInt16>> LBATT16 = new List<List<UInt16>>();
for (int i = 0; i < NUMCHANNEL; ++i)
{
LBATT16.Add(TBATT16);
}
LBATT16[0].Add((ushort)(0x1155));
It do add an entry but not only to the LBATT16[0] but to all LBATT16 lists. What am I doing wrong here?
You need to move your list creation inside the loop: