W
WildHare
If I have a class and I add it to an ArrayList and then want to access that
class using using the index operator (e.g. ArrayList[x]) the ArrayList
returns a type "Object". I can cast the return to the correct type (my
class) but that will lead to very convoluted calls to get embedded elements
or to call methods.
For example:
I have a class called "Field"
I Add Fields to the ArrayList with ArrayList.Add(Field)
I can get a Field back by calling
Field returnfield = (Field)ArrayList[x]; // x is the index returned from
the Add() method above
If Field has a function, for example GetValue() the call to get the value
looks like this:
string TheValueIWant = ((Field)ArrayList[x]).GetValue(); // this works but
is cumbersome!!!!
SO...the question is....
How can I make the return of ArrayList[x] be of type "Field" rather than of
type "Object"?
I hope this is clear!!!
class using using the index operator (e.g. ArrayList[x]) the ArrayList
returns a type "Object". I can cast the return to the correct type (my
class) but that will lead to very convoluted calls to get embedded elements
or to call methods.
For example:
I have a class called "Field"
I Add Fields to the ArrayList with ArrayList.Add(Field)
I can get a Field back by calling
Field returnfield = (Field)ArrayList[x]; // x is the index returned from
the Add() method above
If Field has a function, for example GetValue() the call to get the value
looks like this:
string TheValueIWant = ((Field)ArrayList[x]).GetValue(); // this works but
is cumbersome!!!!
SO...the question is....
How can I make the return of ArrayList[x] be of type "Field" rather than of
type "Object"?
I hope this is clear!!!