How can I reduce these four lines of code that splits/trims a semicolon list to one line?
c#, split
Solution
You need to use `Select` if you want to perform a transformation on each instance in the `IEnumerable<T>`.
List<string> values = list.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
Problem
How can I do this: ``` string list = "one; two; three;four"; List<string> values = new List<string>(); string[] tempValues = list.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries); foreach (string tempValue in tempValues) { values.Add(tempValue.Trim()); } ``` in one line, something like this: ``` List<string> values = extras.Split(';').ToList().ForEach( x => x.Trim()); //error ```