tut*_*ain 3 c# generics ado.net compiler-errors
我试图实现一个返回通用列表(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不被识别为通用类型?
你需要告诉方法什么是"T",现在你的方法不知道T是什么.T在编译时已知,语言不能当场计算出类型.
这是一个例子: static List<T> GetInitializedList<T>(T value, int count)
参考这里:http://www.dotnetperls.com/generic-method
| 归档时间: |
|
| 查看次数: |
3634 次 |
| 最近记录: |