相关疑难解决方法(0)

找不到类型或命名空间名称"T"

我有以下代码,我正在.NET 4.0项目中编译

namespace ConsoleApplication1  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  

        }  
    }  

    public static class Utility  
    {  
        public static IEnumerable<T> Filter1(this IEnumerable<T> input, Func<T, bool> predicate)  
        {  
            foreach (var item in input)  
            {  
                if (predicate(item))  
                {  
                    yield return item;  
                }  
            }  
        }  
    }  
}  
Run Code Online (Sandbox Code Playgroud)

但得到以下错误.我已将System.dll作为默认值包含在引用中.我可能做错了什么?

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

Error   2   The type or namespace name 'T' could not …
Run Code Online (Sandbox Code Playgroud)

c# generics

41
推荐指数
3
解决办法
6万
查看次数

无法创建通用方法:找不到"T"

我试图实现一个返回通用列表(List)的方法,但我不断收到此错误消息:

找不到类型或命名空间名称"T"(您是否缺少using指令或程序集引用?)

这是我的方法代码:

public static List<T> doQuery(string query)
{
    SQLiteCommand com = new SQLiteCommand(query, SQLiteManager.connection);
    SQLiteDataReader reader = com.ExecuteReader(CommandBehavior.Default);
    while (reader.Read())
    {
        //other code
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么在这种情况下T不被识别为通用类型?

c# generics ado.net compiler-errors

3
推荐指数
1
解决办法
3634
查看次数

标签 统计

c# ×2

generics ×2

ado.net ×1

compiler-errors ×1