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.