Arrays are zero indexed.
arrayList[0] is the first element of your array
arrayList[1] is the second element of your array
- moduleList.Add(module1Info); // This is setting moduleList[0] to module1Info
-
moduleList.Add(module2Info); // This is setting moduleList[1] to module2Info
- foreach (ArrayList arrayList in moduleList)
the first time through this loop 'arrayList' will contain moduleList[0]
the second time through this loop 'arrayList' will contain moduleList[1]
- arrayList [1].caption = "jo"; // just wrong
the first time through the foreach loop arrayList will be moduleList[0] which is module1Info.
So at that point arrayList[1] might as well say module1Info[1] so we could re-write the line as:
module1Info[1].Caption = "jo";
Since module1Info[1] is really struct2.obj we could further re-write this line as:
struct2.obj.caption
Now do you see why it doesn't work? Because you need struct2.caption not struct2.obj.caption
Let's look at the ArrayList that is module1Info[1]
- ArrayList module1Info = new ArrayList();
-
module1Info.Add(Class1.obj); // module1Info[0]
-
module1Info.Add(struct2.obj); // module1Info[1]
module1Info[1] is struct2.obj because that's what you assigned to it.
I have no idea what .obj property is of your struct2 because you don't show that in your code: You only show the .Caption property. But whatever the .obj property is, that is what you are assigning to module1Info[1]
If you were using classes then you could actually do:
Class2.obj.Caption
But you aren't using classes. You are using structs. Structure don't allow you to nest data like this.