C# understanding a double[...] list

I am trying to understand double[…] list better.
After using different ways of typing I cannot figure out what I am doing wrong :thinking:
I hope it is a typing error but I cannot find it.
The code is based on a past post of someone else.

question6.gh (12.5 KB)

HI YellowLion
You should study the C# basic tutorial.There are several errors in your code.
1:Method calls do not need to write parameter types.
2:You write Distance as distance.

3:You have already created double min and cannot create it again
For the definition of the array, you can check this link

question6.gh (7.0 KB)

1 Like

Thank you for your time helping me :slight_smile:
I looked at the examples and now understand that an array is a rigid-kind of list which does not allow any items to be added. But,

sequence.Resize(ref sequence ,sequence.Length + 5);


1.By resizing, do you know if it takes more memory as like with the List<double> situation wherein every number you add costs memory, doing sequence.Resize?

2.When looking to the examples you gave me, the following of the correct code you gave me is not yet clear to me. So, I understand max + 1 makes a list length of for example 5 + 1 but why you put an (int) in it? Because index-numbers/items can only be 0,1,2,3,4,5 right :slight_smile:

double[] sequence = new double[(int) max + 1];

The notation (int) is new for me, I now know, it has to be written like that, but if it is something typical and I have to remember it for somewhere else in the future, hmmm :thinking:
3.Is (int) a typical/familiar thing?

You can use ArrayList,https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=netcore-3.1

1 Like

No, no, no, do not use ArrayList. That’s a leftover collection type from .NET 1.0 when they didn’t support genetics yet. Use either List<T> or T[]. If you don’t know how many items you’re going to add you can use list, or if you need a shared collection which changes over time. However I’d recommend using arrays as often as possible. Arrays are pretty stark and limited, but that actually helps you really think deeply about your algorithm.