C# ArrayList calling on a constructor class
Posted
by EvanRyan
on Stack Overflow
See other posts from Stack Overflow
or by EvanRyan
Published on 2010-04-27T15:19:09Z
Indexed on
2010/04/27
15:23 UTC
Read the original article
Hit count: 359
I'm aware that an ArrayList is probably not the way to go with this particular situation, but humor me and help me lose this headache.
I have a constructor class like follows:
class Peoples
{
public string LastName;
public string FirstName;
public Peoples(string lastName, string firstName)
{
LastName = lastName;
FirstName = firstName;
}
}
And I'm trying to build an ArrayList to build a collection by calling on this constructor. However, I can't seem to find a way to build the ArrayList properly when I use this constructor. I have figured it out with an Array, but not an ArrayList.
I have been messing with this to try to build my ArrayList:
ArrayList people = new ArrayList();
people[0] = new Peoples("Bar", "Foo");
people[1] = new Peoples("Quirk", "Baz");
people[2] = new Peopls("Get", "Gad");
My indexing is apparently out of range according to the exception I get.
© Stack Overflow or respective owner