C# "cannot assign field because it is a foreach iteration variable"
c#, foreach
Solution
You can do it on the same line as the `Add()` call. No need to overwrite the variable `field` if you pass the result of `Trim()` directly to `Add()`.
foreach (string field in fields)
{
headers.Add(field.Trim());
}
Problem
I want to trim the column headers of a CSV file, fields below is an array that contains the header names, where would I place trim()? I've placed it with the foreach loop but VS tells me "cannot assign field because it is a foreach iteration variable". What am I doing wrong? ``` while ((fields = csv.GetCSVLine()) != null) { if (header) { foreach (string field in fields) { //field = field.trim(); //VS: "cannot assign field because it is a foreach iteration variable" headers.Add(field); } } ```