Reputation: 27265
In .NET which data type do you use to store list of strings ?
Currently I'm using List(Of String)
because it's easier than Array
to manage and add/remove stuff. I'm trying to understand what are the other options, when they become handy and when I should avoid List(Of String)
usage.
Do you use another type? Why and When?
Upvotes: 3
Views: 2477
Reputation: 269328
I think the name says it all really: in most circumstances List(Of String)
is the best way to store a list of strings.
Upvotes: 2
Reputation: 14956
System.Collections.Specialized.StringCollection is also an option, but personally I prefer List(Of String).
Upvotes: 2
Reputation: 42105
Almost always List<string>
or Dictionary<TKey, string>
.
List for when you need an index-based list, and Dictionary when you want random access to a string value given a specified key.
However, try to stick to IList<string>
and IDictionary<TKey, string>
where possible, of course.
Upvotes: 2
Reputation: 1500065
List(Of String)
is a perfectly good way of storing a list of strings. If you need to add/remove elements from in the middle, you might want to consider using a LinkedList(Of String)
but for most situations List
is fine.
Upvotes: 4