On 2007-11-02 13:18:22 -0700, sjoshi <sj****@ingr.comsaid:
Is List.ConvertAll the only way to apply TrimStart to elements of a
List<stringor is there a better way ?
Currently I'm doing this...
List<stringlst = new List<string>();
lst.AddRange(new string[] {"A test", " that you", " need to see!" });
lst = lst.ConvertAll<string>(delegate(string line) { return
line.TrimStart(null); });
Since the String class is immutable, I think the List.ConvertAll()
method is a reasonably nice solution. You'll need _some_ sort of code
that replaces each list element with a new item, and that's pretty much
what ConvertAll() is for.
Other than an explicit for() loop indexing each list element, I don't
see any obvious alternative that is similarly compact and easy-to-read.
Is there something specific about List.ConvertAll() that you don't like?
Pete