c# - 在c#中遍历2行相同的列表
问题描述
- 我正在尝试使用“for循环”遍历 (List<List>),然后在添加到文本框中下一行的相应列时找到所选列的总和。即第 1 行的列添加到第 2 行的列,然后创建一个具有总和值的新行。文本框中的行值:
03 06 16 18 58
20 43 51 55 15
08 24 43 28 39
- 在上面添加行列值之后,我希望有两行的列值如下: 需要的值:
23 49 67 73 73
28 67 43 83 54
- 我尝试了以下方式,但它并没有总结所有三行。我真的不知道我哪里弄错了!
for (int row1 = 0; row1 < textinsideTextbox.Count - 1; row1++)<br/>
{
for (int nextRow = row1 + 1; nextRow < textinsideTextbox.Count - 1; nextRow ++)
{
for (int columnselector = 0; columnselector < availableColumns.Count; columnselector++) //number of columns
{
int valuesRequired = textinsideTextbox[row1][columnselector] + textinsideTextbox[nextRow][columnselector];
}
}
}
解决方案
您可以使用Zip
两次:一次组合列表对,一次组合数字对:
var ans = src.Zip(src.Skip(1),(l1,l2) => l1.Zip(l2, (n1,n2) => n1+n2).ToList()).ToList();
推荐阅读
- unity3d - DontDestroyOnLoad GameObject 上 AudioSource 中的 MissingReferenceException
- amazon-cloudformation - Tachyon 图像处理 - CloudFront 配置 - 指定的密钥不存在 - NoSuchKey
- java - 为什么我不能使用 get 方法访问另一个类中声明的 TreeMap
- algorithm - 双连通分量
- unity3d - 这是什么统一错误?Addr2Line 故障
- css - 如何使用 Bootstrap 网格在整个页面宽度上插入背景图像?
- angular - 如何将组件加载到另一个
- ruby-on-rails - 当我在rails中的form_for中使用实例变量时如何发送参数
- javascript - 仅当进程持续超过 500 毫秒时才运行代码
- javascript - 错误:类型 LoginComponent 是 2 个模块声明的一部分:LoginModule 和 AppModule