tags:

views:

111

answers:

3

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?

A: 

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();
Darin Dimitrov
A: 

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();
hmemcpy
+8  A: 
Repeater rpt;

rpt.DataSource = new[] { new { ID = 10 } };
rpt.DataBind();
Timwi