title: What is the fastest way to select data with LINQ by keys collection?
body: <p>There is the following issue:
  you have an  </p>
  
  <pre><code>IEnumerable&lt;TClass&gt; collection
  </code></pre>
  
  <p>where TClass looks like this</p>
  
  <pre><code>public TClass
  {
      public Guid Id {get;set;}
      public string Value {get;set;}
  }
  </code></pre>
  
  <p>Also you have an</p>
  
  <pre><code>IEnumerable&lt;Guid&gt; ids
  </code></pre>
  
  <p>that contains ids if needed TClass objects. You know for sure that <strong>collection</strong> contains TClass objects with ids were given. </p>
  
  <p>I know two ways to get TClass objects by an ids collection:</p>
  
  <p>1)</p>
  
  <pre><code>var result = collection.Where(x =&gt; ids.Any(id =&gt; x.Id.Equals(id)));
  </code></pre>
  
  <p>2)</p>
  
  <pre><code>var result = collection.Join(ids, x =&gt; x.Id, id =&gt; id, (x, id) =&gt; x);
  </code></pre>
  
  <p>So what is the best practice and the fastest way to get a TClass collection by an ids collection? Maybe you know an another way?</p>