日期:2014-05-17  浏览次数:20403 次

三元表达式。。。。########################### 100%结贴
  sList = sObj.GetListInfo(condition, "");
            string b = sList[0].Remark.Length > 10 ? sList[0].Remark.ToString().Substring(0, 10) + "..." : sList[0].Remark;
            var result = from a in sList
                         select new
                         {
                             a.ID,
                             a.GoodsName,
                             a.StartTime,
                             a.endTime,
                             a.StartingPrice,
                             a.SuggestPrice,
                             a.AuctionNumber,
                             a.State,
                             Remark = a.Remark.Length > 10 ? a.Remark.ToString().Substring(0, 10) + "..." : a.Remark
                         };
            anp.RecordCount = result.Count();
            this.gv.DataSource = result.Skip((anp.CurrentPageIndex - 1) * anp.PageSize).Take(anp.PageSize);


这句“Remark = a.Remark.Length > 10 ? a.Remark.ToString().Substring(0, 10) + "..." : a.Remark” 有什么问题吗?为什么会报错未实例化对象这个错误,当我把这句改成Remark = a.Remark就不会有错误啦, 当时我调试时那句 string b 没有问题,。。求解
LINQ select