c# - C#多维列表
问题描述
这是我当前的工作代码。
List<double> values = new List<double>();
foreach (string row in rows)
{
Print(row);
//Checking if the row contains 4 numbers after the " ".
//If true, then added to the collection
if (Regex.IsMatch(row, @" (\d{4})"))
values.Add(double.Parse(Regex.Match(row, @" (\d{4})").Groups[1].Value));
}
foreach (double i in values)
{
Print("row value " + i);
}
我还想做的是解析“”之前的4个数字,并且在如上所述遍历每一行时有2个变量。
我试图通过在网上搜索来解决这个问题,我得到的最接近的结果如下,但我不知道如何循环?
List<string[]> grid = new List<string[]>();
//Populate the list
foreach (var line in lines) grid.Add(line.Split(' '));
//Print(grid);
//You can still access it like your 2D array:
Print(grid[0][0] + " " + grid[0][1]);
提前感谢您的帮助/建议。
解决方案
像这样的东西?
foreach(var array in grid)
{
Print(array[0] + " " + array[1]);
}
我已经节点添加了任何安全检查,您需要检查是否有足够的元素需要,否则您会得到索引超出范围异常
推荐阅读
- deep-learning - 在 Pytorch 上连接 googlenet 的分支(不同维度)
- python - 为什么我的 print() 输出打印在两行上?
- sql - SQL删除除了选择结果
- c# - 使用类库项目从 JSON 文件中读取数据
- asp.net-core - 从 Swagger Doc 中删除 AspnetVersioning ApiVersion
- javascript - Ramda:从谓词数组中拒绝
- python - 如何在不使用 XPath 的情况下使用 selenium 获取元素 Datetime?
- node.js - Nodejs不接收jsondata
- python-imaging-library - 如何在 Pillow 中设置后备字体?
- c++ - 在 malloc() 之后声明向量时出错