//实体类 public class SummaryWord { public SummaryWord(int sumId, string sumName, Int16 type) { SumId = sumId; SumName = SumName; Type = type; } public int SumId { get; set; } public string SumName { get; set; } public Int16 Type { get; set; } }
实现方式:
protected string LinqSample() { StringBuilder html = new StringBuilder(); List<SummaryWord> list = new List<SummaryWord>(); list.Add(new SummaryWord(1, "速度快", 1)); list.Add(new SummaryWord(2, "大气漂亮", 1)); list.Add(new SummaryWord(3, "电池不够用", 2)); var query = from a in list where (a.Type == 1) select a; var queryList = query.ToList(); foreach (var obj in queryList) { html.AppendLine("" + obj.SumName); } return html.ToString(); }
页面调用的代码:
<div> <%=LinqSample()%> </div>
这两个不一致导致的。
楼上好眼力,膜拜之!小学生来看看!