Performance concern: StringCollection vs List

后端 未结 3 646
我在风中等你
我在风中等你 2021-02-01 14:37

I was wondering when I should use List< string > and when I should use StringCollection.

Let\'s say that I have to deal with large

3条回答
  •  不思量自难忘°
    2021-02-01 15:06

    In terms of performance and efficiency, they will be very similar.

    List 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 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.

提交回复
热议问题