push_back operation in c# containers
13,753
Solution 1
It does support List<T>.Add
. Isn't that what you are looking for?
Solution 2
You won't get a direct equivalent to vector
in C# because you have no control over how the memory is allocated. std::vector
will always have its memory in a contiguous block; so if needed, you could access it like so:
std::vector<int> v;
// add items to v
CallSomeCFunction(&v[0]);
C# gives you no control over how the memory is allocated, so the distinction between a vector/array and a list is non-existent. You can use the List
container is what you want.
Comments
-
lexeme almost 2 years
I need container like c++ vector. Often it is adviced to use List, but it dosen't support push_back operation. I know this is rather simple implementing an extension method for List container. But. Would Stack be a good alternative?
Thanks!
-
lexeme over 13 yearsThanks! Because I thought it corresponds to push_front
-
ronag over 13 yearsActually, I believe ArrayList<> is stored in contiguous memory.
-
Zac Howland over 13 yearsmsdn.microsoft.com/en-us/library/… - I've never seen anything stating that in any previous documentation either. With the way the GC works, it would be almost impossible to enforce.