简体   繁体   中英

How can I search a list of objects that contains a list of objects for the first entry that contains an element matching my search criteria?

I have a List of IJapaneseDictionaryEntry objects:

public interface IJapaneseDictionaryEntry
{
    int Sequence { get; }
    IEnumerable<IKanji> Kanjis { get; }
    IEnumerable<IReading> Readings { get; }
    IEnumerable<ISense> Senses { get; }
}

Where each object contains a list of IKanji objects

public interface IKanji
{
    string Text { get; }
    IEnumerable<KanjiInformation> Informations { get; }
    IEnumerable<Priority> Priorities { get; }
}

Here's the list:

List<IJapaneseDictionaryEntry> entries = dictionary.GetEntries().ToList();

If this was a simple list then I know how to search it.

But what I would like to do is to search for the first IJapaneseDictionaryEntry object where there the IEnumerable<Kanji> object inside that contains the text

Can anyone give me any suggestions on how I can do this?

entries.First(x => x.Kanjis.Any(y => y.Text.Contains("犬")))

尝试:

entries.FirstOrDefault(x => x.Kanjis.Any(t => t.Text?.Contains("犬")));

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