开发者

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:

  • program starts
  • program creates a master array which holds GenericClass< T >(param)
  • each generic class then creates an array of type T

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 开发者_Python百科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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜