繁体   English   中英

如何以编程方式删除自定义集合中的行

[英]How to programmatically delete a row in custom collection

我有使用Linq创建的自定义对象的集合。 自定义对象的属性之一是类型。 它可以是“ D2”或“ S1”。 如果恰好是“ D2”,则其中两行的类型可能为“ D2”,这两行中的一行将具有9位数字的ID,另一行将具有11位数字。 在这两行中,我必须删除ID为9位数的行。 如果集合只有一行“ D2”,那么我什么也不做。 以下代码显示了我如何检查集合中是否有两行“ D2”。 我需要删除包含9位ID的行的帮助。

if (customerDetails.Count(i => i.Type == "D2") > 1)
{
    //additional code to remove nine digit id goes here                  
}

谢谢

也许这样的事情对您有用吗?

if (customerDetails.Count(i => i.Type == "D2") > 1) 
{
    //additional code to remove nine digit id goes here                  
    var remainingRowCount = customerDetails.RemoveAll(c => c.Type == "D2" && c.ID.ToString().Length == 9);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM