title: Elegant C# method to return an IEnumerable<T> from a function which is bool TryParse<T>(Input, out T) and an input[,]
body: <p>Is there an elegant way to build an <code>IEnumerable&lt;T&gt;</code> from </p>
  
  <pre><code>bool TryParse&lt;T&gt;(Input, out T) 
  </code></pre>
  
  <p>and an input of type</p>
  
  <pre><code>Input[,]
  </code></pre>
  
  <p>Basically I have a 2D array of Input and would like to call TryParse on each Input, if <code>TryParse&lt;T&gt;</code> returns true I will append the return value in 'out' to an <code>IEnumerable&lt;T&gt;</code>.</p>
  
  <p>I can do this easily in a for loop but I wanted something more elegant. This is what I use at the moment:</p>
  
  <pre><code>        var marketInputColl = new Collection&lt;MarketInput&gt;();
          foreach (object o in marketInputs)
          {
              MarketInput mktInput;
              if (ExcelCache.TryGetCache&lt;MarketInput&gt;(o.ToString(), out mktInput))
                  marketInputColl.Add(mktInput);
          }
  </code></pre>