简体   繁体   中英

C# Linq select object in List where int in object child List<int> occurs n times

I have a List<TestObj> ListOfTestObjs of type

public class TestObj
{
    public List<int> Ints;
}

How do i perform a Linq query that returns an object in the list if the case is that a given integer x occurs n times, and returns null if not? Something like this:

ListOfTestObjs.FirstOrDefault(l => l.Ints == x occurs 3 times in Ints)

Thanks in advance

如果x是您要查找的数字, n是内部集合中应出现的次数:

ListOfTestObjs.FirstOrDefault(l => l.Ints.Count(i => i == x) == n);

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