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?
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?
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();
Repeater rpt;
rpt.DataSource = new[] { new { ID = 10 } };
rpt.DataBind();