title: How do I get an item in a List<> based on an integer field?
body: <p>I have a List&lt;> in my program, filled with my custom class. I want to be able to extract an object from the list by simply specifying an integer, then returning all objects that have an integer property set to that integer. I was thinking of doing it like this:</p>
  
  <pre><code>int exampleint = 5;
  List&lt;MyClass&gt; extract = new List&lt;MyClass&gt;();
  for(int i = 0; i &lt; list.Length; i++) {
      if(list[i].Number == exampleint)
          extract.Add(list[i]);
  }
  return extract;
  </code></pre>
  
  <p>Is there any better or faster way do do this? Just wondering.</p>
  
  <p>Update: Chris, your answer was a little off. This:</p>
  
  <pre><code> List&lt;MyClass&gt; extract = list.FindAll(delegate(int obj) { return obj.Number == exampleint; });
  </code></pre>
  
  <p>should in fact be this:</p>
  
  <pre><code>List&lt;MyClass&gt; extract = list.FindAll(new Predicate&lt;MyClass&gt;(delegate(MyClass obj) { return obj.Number == exampleint; }));
  </code></pre>
  
  <p>Your first example gave me errors. But thanks for pointing me in the right direction, it seems to work now.</p>