gpt4 book ai didi

c# - 如何选择对包含多行 LIST 的条目使用 LINQ?

转载 作者:行者123 更新时间:2023-11-30 16:38:13 24 4
gpt4 key购买 nike

我有一个 IJapaneseDictionaryEntry 对象列表:

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

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

我正在做这样的 LINQ 查询:

var a = entries.SelectMany(x => x.Kanjis)
.Select(x => new { x.Text, x.Priorities });

有没有一种方法可以过滤它,以便我只检索至少具有一个优先级的条目?

最佳答案

你可以使用Eumerable.Where:

var a = entries.SelectMany(x => x.Kanjis)
.Where(x => x.Priorities.Any())
.Select(x => new { x.Text, x.Priorities });

或者在查询语法中:

var e =
from entry in entries
from kanji in entry.Kanjis
where kanji.Priorities.Any()
select new { kanji.Text, kanji.Priorities };

关于c# - 如何选择对包含多行 LIST 的条目使用 LINQ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55531174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com