IEnumerable.Select with index

后端 未结 3 1075
一生所求
一生所求 2020-12-20 14:15

I have the following code:

 var accidents = text.Skip(NumberOfAccidentsLine + 1).Take(numberOfAccidentsInFile).ToArray();

where accidents i

3条回答
  •  無奈伤痛
    2020-12-20 14:35

    Use Enumerable.Range to generate the ID values and then use the current value to index into your String Array:

    Enumerable.Range(0, accidents.Length).Select(f => new Accident() { Id = f, Name = accidents[f] })
    

提交回复
热议问题