C# 一般列表法问题

C# 一般列表法问题,c#,generics,list,C#,Generics,List,尝试创建具有以下签名的方法时出错: 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?) 公共列表CreateList(数据集) 错误1找不到类型或命名空间名称“T”(是否缺少using指令或程序集引用?)

尝试创建具有以下签名的方法时出错:

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?)
公共列表CreateList(数据集)
错误1找不到类型或命名空间名称“T”(是否缺少using指令或程序集引用?)
有人知道我做错了什么吗


提前谢谢

T
必须在方法级别声明:

public List<T> CreateList<T>(DataSet dataset)
公共列表CreateList(数据集)
或在包含类级别:

public class Foo<T>
{
    public List<T> CreateList(DataSet dataset)
    {
        ...
    }
}
公共类Foo
{
公共列表CreateList(数据集)
{
...
}
}
但请注意不要在两处声明:

// Don't do this
public class Foo<T>
{
    public List<T> CreateList<T>(DataSet dataset)
    {
        ...
    }
}
//不要这样做
公开课Foo
{
公共列表CreateList(数据集)
{
...
}
}

T
必须在方法级别声明:

public List<T> CreateList<T>(DataSet dataset)
公共列表CreateList(数据集)
或在包含类级别:

public class Foo<T>
{
    public List<T> CreateList(DataSet dataset)
    {
        ...
    }
}
公共类Foo
{
公共列表CreateList(数据集)
{
...
}
}
但请注意不要在两处声明:

// Don't do this
public class Foo<T>
{
    public List<T> CreateList<T>(DataSet dataset)
    {
        ...
    }
}
//不要这样做
公开课Foo
{
公共列表CreateList(数据集)
{
...
}
}

因为您定义的是泛型方法,所以类型占位符应该是方法声明的一部分,而不仅仅是其返回类型的一部分。尝试:

public List<T> CreateList<T>(DataSet dataset)
公共列表CreateList(数据集)

因为您定义的是泛型方法,所以类型占位符应该是方法声明的一部分,而不仅仅是其返回类型的一部分。尝试:

public List<T> CreateList<T>(DataSet dataset)
公共列表CreateList(数据集)

谢谢你的回答,帮我解决了很多问题!谢谢你的回答,帮了我很多忙!