Skip to content

Question: If it is possible to call the attributes of the objects that are the ArrayList elements? HELP!!!

lunastya

Asked Mar 25, 2006, 6:16 PM EST1 answer
Share
LinkedInX
I make the objects of my own class and want to organize them onto the ArrayList (System.Collections.ArrayList), but I cann't use methods and fields of my class objects when they become the elements of the ArrayList. It is possible when I organize the objects into the Array. For me the ArrayList is more suitable.
If it is possible to call the methods and fields of the selfmade class objects that are ArrayList elements?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Sure, if I think I know what you are asking then this is easily done. ArrayList arent "typed" they just hold whatever you put in them. so each element needs to be cast as the type you put into it. You said that you made your own class and we will assume it is called "MyClass" for ease of use, and that the ArrayList is called MyArray. you could do something like this ((MyClass)MyArry[0]).SomeFunctionFromYouClass();
    0