You have a few issues here:
- first, strings are immutable, so when you call
.Replaceyou return a new string. Callingn.Replacedoesn’t modifyn. - assigning to
nin your anonymous function won’t affect the value that’s in your list. - regardless of the above, you can’t change the content of your collection while enumerating it, because it’ll invalidate the enumeration.
Since it seems you’re changing every string in your list, it seems unnecessary to try to modify the collection in-place. Therefore, the succint solution would be to use Linq would to create a new list:
var newList = metricList.Select(s => s.Replace("XX", "1")).ToList();