问题描述
publicstaticList<Data>Getlist(){List<Data>d=newList<Data>();Datar=null;stringsql="select*fromProductsORDERBYprosortorderasc";foreach(DataRowdrinQuery.Getdataset(sql).Tables[0].Rows){d.Add(r=newData(){id=Convert.ToInt32(dr["id"]),ProSortOrder=Convert.ToInt32(dr["ProSortOrder"]),ProLookCount=Convert.ToInt32(dr["ProLookCount"]),ProClassId=Convert.ToInt32(dr["ProClassId"]),ProName=dr["ProName"].ToString(),ProContent=dr["ProContent"].ToString(),ProKey=dr["ProKey"].ToString(),ProDescp=dr["ProDescp"].ToString(),ProBigPic=dr["ProBigPic"].ToString(),ProSmallPic=dr["ProSmallPic"].ToString(),ProAttName=dr["ProAttName"].ToString(),ProAttValue=dr["ProAttValue"].ToString()});}returnd;}为什么在2.0下这段代码错误在3.5下就没事呢
解决方案
解决方案二:
.net2.0没有初始化构造器这个语法糖。r=newData(){...}<--初始化构造器修改为:Datar=newData();r.id=...;r.ProSortOrder=...;