I have a list of strings. All of the strings have whitespace that needs to be converted to underscores. I am fully capable of using a for
or foreach
loop to do this. I am still relatively new to C# and would like to become more familiar with it. With that said, my question is:
How can I get the following code to work in .NET 2.0? When I check fieldList
at the end of the ConvertAll
operation, nothing has changed. Is there an issue with passing the string by value instead of reference?
string fields =
"First Name,Middle Name,Last Name,Birth Date,Gender,Address,City,State,Zip,Email";
List<string> fieldList = new List<string>(fields.Split(','));
fieldList.ConvertAll<string>(new Converter<string, string>(
delegate(string str)
{
str = str.Trim();
str = str.Replace(' ', '_');
return str;
}
));
Please, keep in mind, that I am using .NET 2.0 and cannot currently switch, so I do not have the luxury of using LINQ or Lambdas.