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

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, … Read more

What should I use an IEnumerable or IList? [duplicate]

Generally speaking, you should try and use the least specific type that suits your purpose. IEnumerable is less specific than IList (IList implements IEnumerable) so unless you want something specific from IList (such as Count as you suggest, or perhaps Add, Delete, etc), I’d use IEnumerable. One benefit of remaining with IEnumerable is that you … Read more

Why doesn’t IList support AddRange

Because an interface shoud be easy to implement and not contain “everything but the kitchen”. If you add AddRange you should then add InsertRange and RemoveRange (for symmetry). A better question would be why there aren’t extension methods for the IList<T> interface similar to the IEnumerable<T> interface. (extension methods for in-place Sort, BinarySearch, … would … Read more

C# Syntax – Split String into Array by Comma, Convert To Generic List, and Reverse Order

The problem is that you’re calling List<T>.Reverse() which returns void. You could either do: List<string> names = “Tom,Scott,Bob”.Split(‘,’).ToList<string>(); names.Reverse(); or: IList<string> names = “Tom,Scott,Bob”.Split(‘,’).Reverse().ToList<string>(); The latter is more expensive, as reversing an arbitrary IEnumerable<T> involves buffering all of the data and then yielding it all – whereas List<T> can do all the reversing “in-place”. (The … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)