title: How to Filtering List of Objects using LINQ and Return from a Function
body: <p>I am trying to filter a list of Chord objects (class) in C# using linq.</p>
  
  <p>I have the following function in my class</p>
  
  <pre><code>public List&lt;Chord&gt; FilterDictionary_byKey&lt;Chord&gt;(string theKey)
  {
      var filteredList = from item in _chords
                         where item.KeyName == theKey
                         select item;
  
      return (List&lt;Chord&gt;)filteredList;
  }
  </code></pre>
  
  <p>in the above Chord is an object type, _chords is a class variable of List type.</p>
  
  <p>then from my calling code I tried the following:</p>
  
  <pre><code>List&lt;Chord&gt; theChords = globalVariables.chordDictionary.FilterDictionary_byKey("A");
  </code></pre>
  
  <p>obviously trying to return a filtered list of Chord objects from the class</p>
  
  <p>however, when i compile the compiler returns</p>
  
  <p>Error   1   The type arguments for method 'ChordDictionary.chordDictionary.FilterDictionary_byKey(string)' cannot be inferred from the usage. Try specifying the type arguments explicitly.  C:\Users\Daniel\Development\Projects\Tab Explorer\Tab Explorer\Forms\ScaleAndChordViewer.cs 75  37  Tab Explorer</p>