I have this code that I use to bind to a repeater:
Repeater 开发者_高级运维rpt;
var q = from t in new[] { 10 }
select new { ID = t };
rpt.DataSource = q;
rpt.DataBind();
Is there a simpler way to accomplish this code segment; the var q
part?
Repeater rpt;
rpt.DataSource = new[] { new { ID = 10 } };
rpt.DataBind();
Not really. You could write it like this if you prefer:
var q = new[] { 10 }.Select(t => new { ID = t });
rpt.DataSource = q;
rpt.DataBind();
It doesn't get much simpler than that.
You could inline the variable, so that it becomes:
Repeater rpt = ...;
rpt.DataSource = from t in new[] { 10 }
select new { ID = t };
rpt.DataBind();
精彩评论