关于泛型的一个简单问题!
struct arrWare{
public int id;
public string name;
public string desc;
}
public IList <arrWare> GetWare()
{
IList <arrWare> wares = new List <arrWare> ();
//IList <CustomersM> customer = new List <CustomersM> ();
strSql = "select top 10 infoName,infos,infoId from WareInfo ";
//SqlParameter parms = new SqlParameter( "@id ", SqlDbType.Int);
//parms.Value = id;
using (SqlDataReader rdr = SqlHelper.ExecuteReader(CommandType.Text, strSql, null))
{
arrWare ar = new arrWare();
while (rdr.Read())
{
ar.name(rdr.GetString(0));
ar.desc(rdr.GetString(1));
ar.id(rdr.GetInt32(2));
wares.Add(ar);
}
return ar;
}
}
运行时提示:非泛型 类型“System.Collections.IList”不能与类型参数一起使用
(public IList <arrWare> GetWare())报错
------解决方案--------------------return ar;
返回结构体??但是你方法申明的是IList,这样可