假设:
var a = SomeCollection.OrderBy(...)
.Select(f => new MyType
{
counter = ? //I want counter value, so what first
//object have counter=1, second counter=2
//and so on
a=f.sometthing,
...
});
Run Code Online (Sandbox Code Playgroud)
如何设置此计数器值?或者我喜欢a后来迭代?
使用Select的重载,它可以为您提供当前元素的从0开始的索引.
.Select((item, index) => new MyType
{
counter = index + 1,
a = item.Something
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1511 次 |
| 最近记录: |