有时候大家会用到linq来查询数据,筛选自己想要的数据,比如一组List里面有一个数值你不想加入复制到某一个对象。这时候你可以用 object.Where(p => p.attribute!= attribute/parameter).ToList();然而有时候遍历过程中有参数为null,这将会触发异常,我们可以用下图方法进行解决!
foreach (uint extNo in PCSession.ExtNoList)
{
string extKey = $"DeviceType.ExtNo{extNo}";
if (setting.ContainsKey(extKey))
{
string devType = setting[extKey];
if (devType.ToUpper() == "TS480")
{
lstDetectAgentDict[extNo] = lstDetectAgent.Where(p => $"{p.SeqParams?.Count()}" != "20").ToList();
lstBootDetectAgentDict[extNo] = lstBootDetectAgent;
}
else if (devType.ToUpper() == "C3000")
{
lstDetectAgentDict[extNo] = lstDetectAgent.Where(p => $"{p.SeqParams?.Count()}" != "21").ToList();
lstBootDetectAgentDict[extNo] = lstBootDetectAgent;
}
}
}
Where(p => $”{p.SeqParams?.Count()}” != “20”) 圈起来要考,哈哈!
本站长技术菜的一笔,如有更好的方法,欢迎大佬们留言!
public class Program { public static MyStruct myStruct; public Program() { } public class Student { public int Id { get; set; } pu…
© 版权声明
THE END
暂无评论内容