asp.net - Is it possible to combine these 2 statements using linq? -
using asp.net 4.0/c#
i have list of items. list contains duplicates.
this item class:
public class pingtreenode { public int tierid { get; set; } public int lenderid { get; set; } public int weight { get; set; } public int seq { get; set; } public pingtreenode(int tierid, int lenderid, int weight, int seq) { tierid = tierid; lenderid = lenderid; weight = weight; seq = seq; } }
in first instance want select first item each lenderid. using linq:
var tiernodes = new list<pingtreenode>(); tiernodes = tiernodes.groupby(x => x.lenderid).select(x => x.first()).tolist();
however, want add sequence list, starting 1,2,3 etc. separately looping through this:
int seq = 1; foreach (var t in tiernodes) { t.seq = seq; seq++; }
is possible both group , sequence @ same time using single linq statement?
int seq = 1; var tiernodes = new list<pingtreenode>(); tiernodes = tiernodes .groupby(x => x.lenderid) .select(x => { var y = x.first(); y.seq = seq++; return y; }) .tolist();
Comments
Post a Comment