D
David Anton
Jon Skeet [C# MVP]wrote:
"]David Anton
need to call ToString() if you just cast. (That's a conversion of
reference type, but not of actual object.)
I would never (or at least, almost never) call ToString() on ArrayList
items to get them as strings - if I think they're already strings,
I'll
just cast them to string and get an exception if I turn out to be
wrong. If I know some may not be strings, I'm unlikely to rely on
ToString() doing the right thing. It's only in the rare case where
they'll all be instances of my own class which definitely overrides
ToString() in an appropriate way that I'll call ToString() on them.
--
Jon Skeet - <[email protected]>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me
too[/quote:f1e38a9df2]
Point taken.
I agree with you about calling "ToString" on ArrayList - however, my
main point was that ArrayList is really not appropriate for arrays of
strings - if you know you're dealing with strings then
StringCollection is ideal. I use ArrayList for mainly for lists of
objects that aren't better dealt with in other types of lists.
"]David Anton
ToString() is not a conversion, it's a method call. However, you don'twrote:
You're right about the boxing (I've already fessed up to my error).
But the "ToString" is required - an ArrayList element is not
necessarily a string. And it is a conversion.
need to call ToString() if you just cast. (That's a conversion of
reference type, but not of actual object.)
I would never (or at least, almost never) call ToString() on ArrayList
items to get them as strings - if I think they're already strings,
I'll
just cast them to string and get an exception if I turn out to be
wrong. If I know some may not be strings, I'm unlikely to rely on
ToString() doing the right thing. It's only in the rare case where
they'll all be instances of my own class which definitely overrides
ToString() in an appropriate way that I'll call ToString() on them.
--
Jon Skeet - <[email protected]>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me
too[/quote:f1e38a9df2]
Point taken.
I agree with you about calling "ToString" on ArrayList - however, my
main point was that ArrayList is really not appropriate for arrays of
strings - if you know you're dealing with strings then
StringCollection is ideal. I use ArrayList for mainly for lists of
objects that aren't better dealt with in other types of lists.