list.Take(100).ToList() vs. list.GetRange(0,100)

前端 未结 5 1728
臣服心动
臣服心动 2021-02-19 11:57
List attendees = new List();
foreach ...
// Error: \"There are too many target users in the email address array\"
// for more tha         


        
5条回答
  •  不要未来只要你来
    2021-02-19 12:44

    List.Take(100).ToList(), would be more appropriate if you don't know the number of elements in the list. If it is less than 100, It would just take the ones available. it is more flexible to use this.

    On the other hand, List.GetRange(0,100) assumes that the number of elements in the list is more than 100. You would however get this error ***

    Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection

    ***. if the number of elements is less than the specified range.

    For me, I would say that List.Take(100).ToList() is more generic since it doesn't restrict usage.

提交回复
热议问题