Q:

C# creating labels in Form dynamically from an ArrayList containing Class

I have a programm which should display some labels (10-50). 
I'd like to store the values in an array, for iterating through it. 
I found out how to store different datatypes in an ArrayList. 
I have a Class hdinfoData and I assign it to an array list. 
I thought i have something like a 2D array with different datatypes. 
I can't access the values stored in the array list, since it isn't really a 2D array, it's just an array containing objects (hdinfoData class)
What is the right way to this? 
I'd like to create pairs of labels "Label" "Value" dynamically. 
Furthermore I'd like to change the order. 
ArrayList hdiData = new ArrayList();

hdinfoData a = new hdinfoData();
   a.ID = 1;
   a.Label = "USER";
   a.Value = user;
   a.PosX = 1;
   a.PosY = 2;

hdiData. Add(a);

hdinfoData b = new hdinfoData();
   b.ID = 2;
   b.Label = "HOST";
   b.Value = host;
hdiData. Add(b);

Label[] lbl = new Label[hdiData. Count];

int y = 50;
for (int i = 0; i < hdiData. Count; i++)
{
   int x = 15;

   lbl[i] = new Label();
   lbl[i].Location = new System. Drawing. Point(x, y);
   lbl[i].Text = (string)hdiData[i];
   lbl[i].ForeColor = Color. White;

   Form1.Controls. Add(lbl[i]);
   y += 25;
}    

internal class hdinfoData
{  
 public int ID { get; set; }
 public string Label { get; set; }
 public string Value { get; set; }
 public int PosX { get; set; }
 public int PosY { get; set; }
}

A:

You'd better use List<hdinfoData> instead of ArrayList.  Then just access its elements' fields as any other object fields:
var hdiData = new List<hdinfoData>();
.................
    lbl[i].Text = hdiData[i].Label;

