<p>Aloha</p>

<p>I have a method with (pseudo) signature:</p>

<pre><code>public static T Parse&lt;T&gt;(string datadictionary) where T : List&lt;U&gt;
</code></pre>

<p>This doesn't build. How can I restrict the  in the method to accept only generic List&lt;> objects (which should of cource not contain T's but something else :)</p>

<p>I need to restrict the type of T because I need to call a method on it in this code. The type passed in is a custom collection (based on List).</p>

<pre><code>public class MyCollection&lt;T&gt; : List&lt;T&gt; where T: MyClass, new()
{
    public void Foo();
}


public static T Parse&lt;T&gt;(string datadictionary) where T : MyCollection&lt;U&gt;
{
    T.Foo();
}
</code></pre>

<p>-Edoode</p>

Well, you can have two type parameters:
```
```
public static T Parse<T, U>(string datadictionary) where T : List<U>
```
```
That way you'll also actually know what U is (in a compile-time manner)...
EDIT: Alternatively (and better), just specify the element type and change the return type:
```
```
public static List<T> Parse<T>(string datadictionary)
```
```
e.g.
```
```
List<int> data = Parse<int>(whatever);
```
```
Note that you may wish to change from
```
List<T>
```
to
```
IList<T>
```
or even a broader interface.