C++ Vector like class in C#

10,558

Here is a list with some C++ / C# containers that are roughly equivalent (not exact replacements) to each other:

Share:
10,558
Minas Mina
Author by

Minas Mina

Writing code and learning new stuff is one of the things I truly enjoy! On most days of the week, after work, I work on my own projects: My most notable project is Movie Pal - An app for discovering movies Linked in My LinkedIn profile. My Apps See all of my apps in Play Store. Learning I have an interest in the following technologies: Android (Java, Kotlin) React I am currently learning Python and Machine Learning on Udemy. Languages I speak Greek and English fluently and I am learning Spanish and German on Duolingo.

Updated on June 04, 2022

Comments

  • Minas Mina
    Minas Mina almost 2 years

    What is the analogous class of C++ std::vector in C#?

    I want a class where it keeps an internal array inside and supports insertion at the back in O(1) time.

  • Weyland Yutani
    Weyland Yutani over 10 years
    std::set - HashSet<T> ?
  • Cole Tobin
    Cole Tobin over 10 years
    But the OP wants O(1) insertion time, which doesn't exist in vector or List.
  • Weyland Yutani
    Weyland Yutani over 10 years
    surely vector and list are O(1) insert, doesnt say anything about sorting
  • harold
    harold over 10 years
    OP only asks for O(1) insertion at the back
  • Hamlet Hakobyan
    Hamlet Hakobyan over 10 years
    List<T> have O(1) in add at the back if the size less than capacity. It s very important.
  • w128
    w128 over 10 years
    Using List.Add() can become O(n) operation if capacity change is needed. LinkedList, however, guarantees O(1) back insertion.
  • harold
    harold over 10 years
    List.Add is O(1) amortized, that might count too - actually it probably does, because OP explicitly asks for an array-backed datastructure.
  • Sam
    Sam over 10 years
    @WeylandYutani: neither List<T> nor vector are O(1) for all insertions (only those that happen at index == count, and if a resize occurs this wouldn't be the case either).
  • Weyland Yutani
    Weyland Yutani over 10 years
    ah i was confusing insert in middle with replace
  • CMircea
    CMircea over 9 years
    std::set is equivalent to SortedSet; std::unordered_set is HashSet. Same for std::map.
  • Enamul Hassan
    Enamul Hassan about 8 years
    If you have another question, please ask it by clicking the Ask Question button.
  • Benji Altman
    Benji Altman over 3 years
    std::vector is not backed by a linked list, it specifically stores data contiguously in memory (like an array). Source: cplusplus.com/reference/vector/vector - second paragraph.