Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下 linq 查询productionMachines.OrderBy(x => x.TimeDone).ToList(); 现在我想分配一些属性X,它在集合中的位置索引。就像第一个 productionMachines 将收到X等于 1 秒 2 等等......
productionMachines.OrderBy(x => x.TimeDone).ToList();
X
示例 productionMachines 有 5 个条目。productionMachine[0].X 将有 1 .. .. .. productionMachine[4].X 将有 5
使用另一种形式的选择
productionsMachines.OrderBy(x => x.TimeDone) .Select( (x,i) => { x.Property = i+1; return x; });
int index= 1; productionMachines .OrderBy(p => p.TimeDone) .ToList() .ForEach(p2 => { p2.X = index++; } );