c# linq return 按单元格记录 - 索引器和值

c# linq return records by cells - indexer and Value

我努力为以下任务找出解决方案。

设置:

class Records
{

    Cells cells;

}

class Cell
{

    string FieldName;
    string Value;

}

class Cells : Collection<Cell>
{

    public Cell this[string FieldName]

}

list<Records> records;

程序: 新记录添加到 "records",每条记录包含相同的单元格设置。

目标: 一个 linq 命令,它将 return 所有记录的列表,其中 cell-FieldName 与搜索条件匹配

like: 'select records from records where cells["ItemID"] == "ItemNo"'

你能帮我一下吗?谢谢!

这可以是您的索引器的代码。

public Cell this[string fieldName]
    {
        get
        {
            return records.Where(t=>t.FieldName == fieldName).FirstOrDefault();
        }
    }