Performance concern: StringCollection vs List<String>
I would personally prefer to use List<string>
:
- No need to remember one specific type just for strings
- It implements the generic
IEnumerable<T>
rather than justIEnumerable
, and thus supports LINQ - It's supported in SilverLight
- It's more idiomatic for most developers (IMO)
I would be really surprised to find StringCollection
to be significantly faster than List<string>
- see if you can back that up with numbers. My only cause for hesitation is that GridView
could potentially have hard-coded support for StringCollection
to make it fast with that type - but that sounds pretty unlikely to me.
In terms of performance and efficiency, they will be very similar.
List<string>
might be a little faster actually. It is kindof a wrapper around the pre-generic ArrayList. There's no boxing/unboxing, but there is still an extra step or two under the hood, IIRC.
StringCollection was handy before .NET 2.0 because it was strongly typed to string, very common thing to want a list of. I would suggest using List<string>
now though. Since most framework and 3rd party assemblies will use it rather than StringCollection, this would:
- avoid a lot of casting
- avoid some confusion. Other (especially newer) developers would constantly be wondering what your reason was for using StringCollection.
List<string>
is not a wrapper over ArrayList
It is a new implementation of ArrayList
implemented by having an array (which is resized to the double size when the count
becomes bigger than its length) and a count
property.