---
title: "Improving IEnumerable<T> LINQ query"  
description: "Improving IEnumerable<T> LINQ query"  
author: "Anonymous User"  
published: 2013-05-13  
updated: 2013-05-13  
canonical: https://www.mindstick.com/forum/876/improving-ienumerable-t-linq-query  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Improving IEnumerable<T> LINQ query

Hi Expert! \
Starting with the next entities [definition](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat):\
Public Class [Certificate](https://www.mindstick.com/blog/122/viewing-client-certificate){ public ID as int;}\
Public Class [Authority](https://www.mindstick.com/forum/156108/what-is-domain-authority){ ID int; Certificates IEnumerable<Certificate>;}My [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) recives 2 [collections](https://www.mindstick.com/articles/12458/what-are-collections-in-c-sharp): IEnumerable<Certificate> and IEnumerable<Authority>. I need to select the Authorities which Certificates [collection](https://www.mindstick.com/articles/1718/collections-in-java) has at least \
one Certificate in the IEnumerable<Certificate> input parameter.\
My firt [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) is enumerating the IEnumerable<Certificate> and selecting the Authority using a Where(predicate).\
Public IEnumerable<Authority> SelectAuthorities(authList IEnumerable<Authority>, certList IEnumerable<Certificate>){\
foreach (Certificate loadedCert in certList) { [yield return](https://www.mindstick.com/interview/34101/how-do-you-read-a-file-line-by-line-using-a-generator-like-approach-e-g-yield-return) auth.Where(a => a.Certificados.Any(c1 => c1.IDCert == loadedCert.IDCert)); } \
}I think there must be a way to avoid the [for loop](https://www.mindstick.com/forum/12568/android-for-loop-not-working-in-main-thread) using a more complex linq [correlated](https://www.mindstick.com/interview/624/what-are-correlated-subqueries) subquery (I feel it in the "force") but I can't find it.\
Can anybody help?Thanks in advance!

## Replies

### Reply by AVADHESH PATEL

Hi Chintoo!\
You can use double Any to avoid loop:\
authList.Where(a => a.Certificados.Any(c1 => certList.Any(c2 => c1.IDCert == c2.IDCert)));\
I Hope it helpful to you.


---

Original Source: https://www.mindstick.com/forum/876/improving-ienumerable-t-linq-query

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
