anm*_*rti 6 .net c# ienumerable
有这个代码:
return Enumerable.Repeat<MyClass>(new MyObject
{
Iteration = // Get the current loop index
},
10).ToList<MyClass>();
public MyClass
{
public int Iteration {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
如何Iteration使用该Enumerable.Repeat方法在属性中设置当前循环索引?
Tim*_*ter 13
你可以Enumerable.Range改用:
int count = 10;
List<MyObject> objects = Enumerable.Range(0, count)
.Select(i => new MyObject { Iteration = i })
.ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1251 次 |
| 最近记录: |