views:

522

answers:

4

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?

+4  A: 

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.

Jon Skeet
+2  A: 

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.

Neil Barnwell
+2  A: 

System.Collections.Specialized.StringCollection is also an option, but personally I prefer List(Of String).

Jakob Christensen
+2  A: 

I think the name says it all really: in most circumstances List(Of String) is the best way to store a list of strings.

LukeH