简体   繁体   中英

c# linq return records by cells - indexer and Value

i struggle figuering out a solution for the following Task.

Setup:

class Records
{

    Cells cells;

}

class Cell
{

    string FieldName;
    string Value;

}

class Cells : Collection<Cell>
{

    public Cell this[string FieldName]

}

list<Records> records;

Program: new Records are added into "records", each record contains same Setup of cells.

Goal: a linq-command that will return a list of all records, where cell-FieldName matches with search-criteria

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

Could you please help me with that? Thanks!

This can be code of your indexer.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM