newbie question: A variable size vector in c#/NET

C V 41 Reputation points
2022-11-13T18:38:50.377+00:00

Hi all,

I come from the C/C++ world.
To my surprise, I've discovered that there is no variable size vector with constant access time when you index Nth element.
There is a List<T>, as Generics, that should implement, as far as I've understood, a typical list data structure with insert/remove constant access time
but with linear access time when you index a particular element.

Have I right understood?

thanks

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,304 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 56,926 Reputation points
    2022-11-13T18:49:57.487+00:00

    List<T> are implemented internally as arrays that are resized as required. So access is linear, but adding may require a reallocation and copy. So they are really vectors.

    Dictionary<k,t> are implemented as hash tables.

    The current version of C# also has Span<T> which is stack allocated memory buffer.


0 additional answers

Sort by: Most helpful