如何减少将分号列表拆分/修剪为一行的这四行代码?

Edw*_*uay 3 c# split

我怎样才能做到这一点:

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());
}
Run Code Online (Sandbox Code Playgroud)

在一行中,这样的事情:

List<string> values = extras.Split(';').ToList().ForEach( x => x.Trim()); //error
Run Code Online (Sandbox Code Playgroud)

Ada*_*son 7

Select如果要对其中的每个实例执行转换,则需要使用IEnumerable<T>.

List<string> values = list.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
Run Code Online (Sandbox Code Playgroud)