I have 3 classes and they more or less go like this:
Class a
class a {
b bObject;
public a() {
}
protected override void Draw(GameTime gameTime) {
bObject = new b(); // I know this is bad but I need this here
spriteBatch.Begin();
b.DrawFunction();
spriteBatch.End();
}
}
Class b
class b {
List<c> cList = new List<c>();
int itemAtIndex10;
public b() {
for(int i = 0; i < 32; i++) {
cList.Add(new c { bunch of variables here }); // 32 items in the list
}
}
public void DrawFunction() {
spriteBatch.Draw(drawstuff);
// more code
itemAtIndex10 = cList[10].variable; // This causes an OutOfRangeException?
}
}
Class c
class c {
// Loads of variables here
public c() {
}
}
Why does this cause an OutOfRangeException? The error is telling me it's coming from "cList" even though in class b, I've added 32 items.
I think this line...
Should be this line...
unless i'm mistaken cList is a List, where c is the class c from below.