What's the C# equivalent of C++ vector?
I am searching for this feature:
To have a dynamic array of contiguously stored memory that has no performance penalty for access vs. standard arrays.
I was searching and they say .NET equivalent to the vector in C++ is the ArrayList
, so:
Do ArrayList have that contiguous memory feature?
You could use a List<T>
and when T
is a value type it will be allocated in contiguous memory which would not be the case if T
is a reference type.
Example:
List<int> integers = new List<int>();
integers.Add(1);
integers.Add(4);
integers.Add(7);
int someElement = integers[1];