Here:
for(int i = 0; i < test.Count; i++) {
test[i] = String.Format("Hello {0}", test[i]);
}
No need to be fancy. No need to abuse LINQ. Just keep it simple.
You could go one step beyond this and create an extension method like so:
static class ListExtensions {
public static void AlterList<T>(this List<T> list, Func<T, T> selector) {
for(int index = 0; index < list.Count; index++) {
list[index] = selector(list[index]);
}
}
}
Usage:
test.AlterList(s => String.Format("Hello {0}", s));
Select
is for projecting and is really intended to be used in circumstances where there are no side-effects. Manipulating the items in the list very clearly has side-effects. In fact, the line
test.Select(s => String.Format("Hello {0}", s));
doesn't do anything except creating an IEnumerable<string>
that could eventually be enumerated over to produce the projection.