c# - 我无法在 foreach 循环内的列表中添加项目如何解决?
问题描述
我试图在 foreach 循环内的 myList 中添加一个项目:我总结了问题,让我们考虑 EmployeeInfo 有 1000 条记录,然后 HasValue 没有添加项目。
List<bool> HasValue = new List<bool>();
foreach(var list in EmployeeInfo)
{
if(list.Count() > 0)
{
HasValue.Add(true);
}
else
{
HasValue.Add(false);
}
}
解决方案
这是否有助于您更接近您的答案?
public class EmployeeInfo {
public List<String> TheList { get; } = new List<String>();
}
public void Test(){
var employeeInfo = new EmployeeInfo();
var hasValues = employeeInfo.TheList.Count( list => list.Any() );
var noValues = employeeInfo.TheList.Count - hasValues;
}
推荐阅读
- javascript - 需要在单击按钮时显示 gifloader,该按钮在后端执行一些处理并在处理完成后清除
- html - 无法删除之间的空格
- solr - SolrCloud 中的乐观并发问题
- drake - 使用 >= 进行约束会引发 RuntimeError(请使用 pydrake.common.containers.EqualToDict)
- javascript - 如何确定在图表上绘制 5 的倍数所需的最少 Y 增量?
- api - 使用lua根据ID重定向url
- gradle - 如何使用 Kotlintest 和 Gradle 获得分层测试报告
- c# - 需要在c#中处理unicode字符
- angular - Angular Protractor 更新到 6.0.0 会导致浏览器崩溃
- google-cloud-storage - 使用 XML API 列出 1000 多个存储桶