Redim a String[]

  • Thread starter Thread starter Raymond Du
  • Start date Start date
Jon Skeet [C# MVP]wrote:
"]David Anton
wrote:
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.
ToString() is not a conversion, it's a method call. However, you don't

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 said:
Many people seem to be 'stuck' on ArrayList, but if you know that
you're dealing with strings then a StringCollection will avoid
boxing/unboxing issues and you'll also know that the only thing
you'll have in the StringCollection is strings - each element is a
string - no 'ToString' or conversion or unboxing.

Better to use an arraylist for consistancy.
 
Michael Culleywrote:
"David Anton"
Many people seem to be 'stuck' on ArrayList, but if you know that
you're dealing with strings then a StringCollection will avoid
boxing/unboxing issues and you'll also know that the only thing
you'll have in the StringCollection is strings - each element is a
string - no 'ToString' or conversion or unboxing.
Better to use an arraylist for consistancy.

--
Michael Culley[/quote:06f6a5a18a]

C'mon; live a little! There are at least a dozen interesting types of
lists native to .NET: Hashtables, ArrayList, StringCollection, Stacks,
Queues, NameValueCollections, etc. They all are great tools when used
in the right context.
 
[Please don't just include the previous post without either quoting or
trimming the signature - it makes it much harder to see what's going
on, and harder to reply to as well.]

David Anton said:
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.

StringCollection is certainly more appropriate (if you're not using the
Compact Framework, of course, where it's not present) in those cases,
yes. (On the other hand, using ArrayList everywhere gives a certain
uniformity of access. I must admit to using it "by default" quite
often.)

Fortunately with generics much of this will become a problem of the
past :)
 
Back
Top