What is the initial size of an ArrayList in C #?

I want to know what is the initial size of an ArrayList in C #?

+3
source share
6 answers

0. See below.

16. (I have to add characters to this answer since 18 characters are minimal)

Change, Oops - the initial capacity is 16. The original size, of course, is 0, because it is empty. Have to learn to read. Or you need to learn how to formulate your questions .;)

Change again; The initial capacity of ArrayList in .NET 1.0 is 16. In 2.0 it was 4, and now - with .NET 3.5 - the initial capacty has been lowered to 0. I have no explanation why, you.

​​ 4. , arraylist.Count eq arraylist.Capacity, .

+12

ArrayList Size = 0 ( ) Capacity = 16.

, - O (n), n - . , 5000 , ArrayList - .

- , 5000 , 5000 .

arraylist, , . , Capacity < Count, ArgumentOutOfRange.

+7

.. -, .NET 3.5; .

:

PS> $a = new-object system.collections.arrayList
PS> $a.Capacity
0
PS> $a.count
0

, Reflector, :

public virtual int Capacity
{
    get
    {
        return this._items.Length;
    }
    ...
}

_items object[] ctor.

+5

ArrayList , , .

1, ArrayList . List<T> .

+2
ArrayList list = new ArrayList();

size = 0 before adding elements to the List array, means that there are no elements.

+1
source

Try it yourself.

int capacity = (new ArrayList()).Capacity;

should provide you with initial capacity.

0
source

Source: https://habr.com/ru/post/1720049/


All Articles