我们可以使用 LINQ 来替换这个 foreach 循环吗?
我有这个函数:
public void RemoveCustomAssignmentFromPublishers(int iCustomAssignment)
{
try
{
// We need to examine each Publisher in the dictionary
foreach (KeyValuePair<string, Publisher> entry in _PublisherData.PublisherDictionary)
{
// We must remove all default exclusions where the stated custom assignment index is used
entry.Value.Assignments.CustomAssignments.RemoveAll(x => x.Index == iCustomAssignment);
}
}
catch (Exception ex)
{
SimpleLog.Log(ex);
}
}
它迭代一个映射,然后使用 LINQ 删除指示的所有项目。
我们可以使用 LINQ 代替 foreach
循环吗?
I have this function:
public void RemoveCustomAssignmentFromPublishers(int iCustomAssignment)
{
try
{
// We need to examine each Publisher in the dictionary
foreach (KeyValuePair<string, Publisher> entry in _PublisherData.PublisherDictionary)
{
// We must remove all default exclusions where the stated custom assignment index is used
entry.Value.Assignments.CustomAssignments.RemoveAll(x => x.Index == iCustomAssignment);
}
}
catch (Exception ex)
{
SimpleLog.Log(ex);
}
}
It iterates a map and then uses LINQ to remove all items as indicated.
Can we use LINQ instead of the foreach
loop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论