用于从列表中删除行的 Lambda 语法
假设:
string removeRows = "";
int i = 0;
foreach (var row in userStats)
{
if (row.OrderRow.RegistrationType == "Want Removed")
{
removeRows = removeRows + i.ToString() + ",";
}
i++;
}
执行删除的 Lambda 语法是什么?
Given:
string removeRows = "";
int i = 0;
foreach (var row in userStats)
{
if (row.OrderRow.RegistrationType == "Want Removed")
{
removeRows = removeRows + i.ToString() + ",";
}
i++;
}
what's the Lambda syntax to execute the removal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,您的代码收集要删除的行的索引,并形成一个以逗号分隔的字符串。它实际上并没有删除这些项目,所以我不知道你为什么要这样做。
如果
userStats
是List
,其中T
是您的行类型,则可以使用实际删除的RemoveAll
方法符合给定条件的所有项目:我认为您的代码滥用了字符串,您都使用它们来收集索引和注册类型。我想知道
RegistrationType
是否可以是一个枚举:As I understand, you code collects the indexes of rows to be removed and forms a string with them comma-separated. It doesn't actually removes these items so I don't know why you're doing it.
If
userStats
isList<T>
whereT
is your row type, you can useRemoveAll
method that actually removes all items that match given condition:I think your code abuses strings, you both use them for collecting indexes and for registration type. I wonder if
RegistrationType
could be an enumeration instead: