是的......这是那些日子之一。
public string TagsInput { get; set; }
//further down
var tagList = TagsInput.Split(Resources.GlobalResources.TagSeparator.ToCharArray()).ToList();
tagList.ForEach(tag => tag.Trim()); //trim each list item for spaces
tagList.ForEach(tag => tag.Replace(" ", "_")); //replace remaining inner word spacings with _
两个 ForEach 循环都不起作用。 tagList 只是一个列表。
谢谢!
最佳答案
Trim()
和 Replace()
不会修改调用它们的字符串。他们创建了一个已应用操作的新字符串。
您想使用Select
,而不是ForEach
。
tagList = tagList.Select(t => t.Trim()).Select(t => t.Replace(" ", "_")).ToList();
关于c# - 这个 ForEach 循环有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3208545/