[英]C# LINQ select from list of arrays of strings
I have this data我有这个数据
which is retained in a list of arrays of strings: List<string[]> arrData = new List<string[]>();
它保留在 arrays 字符串列表中:
List<string[]> arrData = new List<string[]>();
. . The list is filled with the following code:
该列表填充了以下代码:
int columnsCount =4;
int rowsCount = 6;
for (int j = 0; j < columnsCount; j++)
{
string[] columnData = new string[rowsCount];
for (int i = 0; i < rowsCount; i++)
columnData[i] = csv[i][j];
arrData.Add(columnData);
}
csv[i][j] gives the value for r1c1 etc., so in the end the list has 4 arrays elements, each array having 6 values. csv[i][j] 给出 r1c1 等的值,所以最后列表有 4 个 arrays 元素,每个数组有 6 个值。
I can alter the code and create a list of lists / dictionaries / whatever is more suitable.我可以更改代码并创建列表/字典/任何更合适的列表。
How can I use LINQ to select the yellow rows, meaning that have "a" in the first array, "g" in the second one and "m" in the third?
如何使用 LINQ 到 select 黄色行,这意味着第一个数组中有“a”,第二个数组中有“g”,第三个数组中有“m”?
IEnumerable<string[]> result = arrData
.Where(arr => arr?.Length > 2 && arr[0] == "a" && arr[1] == "g" && arr[2] == "m");
How can I use LINQ to filter by a list of values in one column (meaning select all rows with "a" or "b" in first column)?
如何使用 LINQ 按一列中的值列表过滤(意思是 select 所有行在第一列中带有“a”或“b”)?
string[] firstColSearch = { "a", "b" };
IEnumerable<string[]> result = arrData
.Where(arr => arr?.Length > 0 && firstColSearch.Contains(arr[0]));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.