C# LINQ select 来自字符串数组列表

C# LINQ select from list of arrays of strings

我有这个数据

保留在字符串数组列表中:List<string[]> arrData = new List<string[]>();。 该列表由以下代码填充:

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] 给出了 r1c1 等的值,所以最后列表有 4 个数组元素,每个数组有 6 个值。

  1. 如何使用 LINQ select 黄色行,即第一个数组中有“a”,第二个数组中有“g”,第三个数组中有“m”?
  2. 如何使用 LINQ 按一列中的值列表进行过滤(意思是 select 第一列中包含“a”或“b”的所有行)?

我可以修改代码并创建一个列表/字典/任何更合适的列表。

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?

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)?

string[] firstColSearch = { "a", "b" };
IEnumerable<string[]> result = arrData
  .Where(arr => arr?.Length > 0 && firstColSearch.Contains(arr[0]));