tags:

views:

51

answers:

3

Hello,

I'm getting an error when I try to create a method with the following signature:

public List<T> CreateList(DataSet dataset)


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

Does anyone know what I'm doing wrong?

Thanks in advance!

+7  A: 

T must be declared either at the method level:

public List<T> CreateList<T>(DataSet dataset)

or at the containing class level:

public class Foo<T>
{
    public List<T> CreateList(DataSet dataset)
    {
        ...
    }
}

But be careful to not declare it at both places:

// Don't do this
public class Foo<T>
{
    public List<T> CreateList<T>(DataSet dataset)
    {
        ...
    }
}
Darin Dimitrov
+3  A: 

Since you're defining a generic method, the type placeholder should be part of the method declaration, not only of its return type. Try:

public List<T> CreateList<T>(DataSet dataset)
Frédéric Hamidi
A: 

try this

public class Test<T> 
{
  public List<T> CreateList(DataSet dataset) { return null; }
}

your error is telling you that what is the type of List becoz your program does not know about the T.

saurabh