Best string container: StringCollection, Collection, List, ArrayList, ..?

后端 未结 2 1017
春和景丽
春和景丽 2020-12-08 09:58

What is the most suitable container just for strings holding in some array with non-predetermined upper boundary, which length is unknown on it\'s creation.

For simp

相关标签:
2条回答
  • 2020-12-08 10:23

    A List<T> would be the most efficient.

    The Collection<T> class is just a wrapper for another type of list, the parameterless constructor initialises the Collection<T> with a List<T>.

    An ArrayList is essentially the same as a List<object>, so you would have to cast the items to String when reading from it.

    A StringCollection is just a type safe wrapper for an ArrayList.

    0 讨论(0)
  • 2020-12-08 10:31

    For what you need, List<string> is probably the most versatile. StringCollection was handy in 1.1, when (without generics) you needed specific classes for typed collections. Collection<string> is handy if you want to subclass it to provide validation etc.

    Either way, in 3.5, LINQ will provide lots of additional methods for them - but without LINQ, List<T> has more features (Find, Sort, etc)

    0 讨论(0)
提交回复
热议问题