Everett
Everett

Reputation: 15

Calling a method with an index on ArrayList in c#

Ok here is my dilemma, I want to create an array of custom objects but then be able to do something like list[index].method call.

as an example:

I can get that part to work ok but then when I try to use my object methods such as

object[] MasterList = new object[MASTER_LIST_SIZE]; 
// add contents to MasterList

MasterList[index].setValueAt(MethodIndex, value);

I get a message that reads object has no method named setValueAt which requires one parameter(s)

I will admit that what I am trying to do is rather dumb and I could probably do it easier with reading a text file or something but if there is a way to do it like this I would like to know how or at least what I am missing.

Upvotes: 1

Views: 731

Answers (1)

ChaosPandion
ChaosPandion

Reputation: 78292

There are a lot of unknowns about what you are doing but my best guess is that you need to cast the result to the type you need.

((GenericClass<T>)MasterList[index]).setValueAt(MethodIndex, value);

Upvotes: 3

Related Questions