title: Creating a Generic Dictionary From a Generic List
body: <p>I am trying to do the following but I think I must be missing something...(fairly new to generics)</p>
  
  <p>(Need to target .NET 2.0 BTW) </p>
  
  <pre><code>interface IHasKey
  {
      string LookupKey { get; set; }
  }
  ...
  
  public static Dictionary&lt;string, T&gt; ConvertToDictionary(IList&lt;T&gt; myList) where T : IHasKey
  {
      Dictionary&lt;string, T&gt; dict = new Dictionary&lt;string, T&gt;();
      foreach(T item in myList)
      {
          dict.Add(item.LookupKey, item);
      }
  
      return dict;
  }
  </code></pre>
  
  <p>Unfortunately, this gives a "Constraints are not allowed on non-generic declarations" error.  Any ideas?</p>