Adding List.add() another list

后端 未结 1 1409
梦如初夏
梦如初夏 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<T>.Add adds a single element. Instead, use List<T>.AddRange to add multiple values.

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

    tripDetailsCollection.AddRange(tripDetails);
    
    0 讨论(0)
提交回复
热议问题