Adding List.add() another list

后端 未结 1 1410
梦如初夏
梦如初夏 2020-12-23 12:57

I have an IEnumerable and I am trying to add the vales in the for-loop to a List. I keep get

1条回答
  •  爱一瞬间的悲伤
    2020-12-23 13:23

    List.Add adds a single element. Instead, use List.AddRange to add multiple values.

    Additionally, List.AddRange takes an IEnumerable, so you don't need to convert tripDetails into a List, you can pass it directly, e.g.:

    tripDetailsCollection.AddRange(tripDetails);
    

    0 讨论(0)
提交回复
热议问题