I want to split this line:
string line = \"First Name ; string ; firstName\";
into an array of their trimmed versions:
\"Fi
Because p.Trim() returns a new string.
You need to use:
List<string> parts = line.Split(';').Select(p => p.Trim()).ToList();
The ForEach
method doesn't return anything, so you can't assign that to a variable.
Use the Select
extension method instead:
List<string> parts = line.Split(';').Select(p => p.Trim()).ToList();