2

Imagine the following method

public void SomeMethod<T>(T param) where T: List<T2> { } 

It doesn't work:

Error 16 The type or namespace name 'T2' could not be found (are you missing a using directive or an assembly reference?)

How do I achieve the what I clearly intended to do?

1
  • What you intend to do is not clear because your title is worded improperly. It should be: "How to specify a generic method to take a parameter that is a generic type?". Commented Jan 5, 2010 at 19:47

2 Answers 2

9

In order to do this, you need to specify an additional generic parameter

public void SomeMethod<T1,T2>(T1 param) where T1 : List<T2> { } 
Sign up to request clarification or add additional context in comments.

Comments

3

As a side answer to the accepted solution, since T is explicitly related to T2, why have T at all?

public void SomeMethod<T2>(List<T2> listParam) { } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.