ForEach is not mutable, it doesn't change the data structure in any way.
You can either:
- Handle the loop yourself, with an index
- Produce a new list, using .Select and .ToList (provided you're using .NET 3.5)
Example of #1:
for (Int32 index = 0; index < myList.Count; index++)
if (myList[index].Trim().Length == 0)
myList[index] = "0.0";
With .NET 3.5 and Linq:
myList = (from a in myList
select (a.Trim().Length == 0) ? "0.0" : a).ToList();
With .NET 3.5, not using the Linq-syntax, but using the Linq-code:
myList = myList.Select(a => (a.Trim().Length == 0) ? "0.0" : a).ToList();
Edit: If you want to produce a new list of doubles, you can also do that in one go using Linq:
List<Double> myDoubleList =
(from a in myList
select (a.Trim().Length == 0 ? "0" : a) into d
select Double.Parse(d)).ToList();
Note that using "0.0" instead of just "0" relies on the decimal point being the full stop character. On my system it isn't, so I replaced it with just "0", but a more appropriate way would be to change the call to Double.Parse to take an explicit numeric formatting, like this:
List<Double> myDoubleList =
(from a in myList
select (a.Trim().Length == 0 ? "0.0" : a) into d
select Double.Parse(d, CultureInfo.InvariantCulture)).ToList();