I need a dynamic length data structure with the capability of changing the element values.
The order of the elements is not important.
-
If I use an array I can modify my elements, but I have problems with the length. The solution is to create a new array of the correct size and copy all the elements into the new one each time. Not a great idea because the number of elements changes often.
-
It’s better to use a generic list, but the modify process is really complicated: first of all I need to remove the element I want to change- the generic list doesn’t seem to have a simple “Remove”/”Delete” method, so I tried the “Filter” one- then add the modified element to the head. It works but it’s a bit too complicated for something so easy.
Is there a data structure that allows me to dynamically change the length and modify the elements such as a modifiable list or a dynamically-sized array?
Use ResizeArray. It’s an abbreviation for the CLI type List(T) which offers the features you require, like Remove for example.
From MSDN Library:
An example in
F#: