is there in C# a method for List like resize in c++ for vector

后端 未结 7 1333
無奈伤痛
無奈伤痛 2021-01-03 18:14

When I use resize(int newsize) in C++ for vector, it means that the size of this vector are set to newsize

7条回答
  •  长发绾君心
    2021-01-03 19:09

    Haven't you read at MSDN:-

    A list is a resizable collection of items. Lists can be constructed multiple ways, but the most useful class is List. This allows you to strongly type your list, includes all of the essential functionality for dealing with collections, and can be easily searched.

    Further:-

    Capacity is the number of elements that the List can store before resizing is required, while Count is the number of elements that are actually in the List.

    Capacity is always greater than or equal to Count. If Count exceeds Capacity while adding elements, the capacity is increased by automatically reallocating the internal array before copying the old elements and adding the new elements.

提交回复
热议问题