我怎样才能做到这一点:
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)
Select如果要对其中的每个实例执行转换,则需要使用IEnumerable<T>.
List<string> values = list.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
190 次 |
| 最近记录: |