score:1

Accepted answer
var counter = 0;
var results =
    from foo in bar
    select new { foo.ID, foo.Name, Counter = ++counter }; 

score:2

With the overload of Select that includes the index (also available for queryables) in fluent-syntax, you can do:

var results = bar.Select((foo, index) => new 
                                         { 
                                             foo.ID,
                                             foo.Name, 
                                             Counter = index + 1 
                                          });

Note that this overload is not available in query-syntax.

score:0

Something like this maybe:

var result= db.bar.Select((foo,i)=>select new {foo.ID, foo.Name, Counter = i+1});

score:0

Use the indexed Select() overload:

var results = bar.Select((foo, i) => new { foo.ID, foo.Name, Counter = i + 1});

Related Articles