Arrays v Lists

So after watching the lecture, I was a little puzzled about when an array would be preferred over a list. All signs seem to point at a list being more versatile (And in the current lecture, a good example being the differing size needed for the waypoints being created.)

Apart from a better performance speed (indicated by the slide used), what are some examples of when someone would actively choose to use an array rather then a list in a unity project?

Hi Chris,

Apart from the performance, I prefer arrays if the order of my elements matters. On a List, you can easily call Sort(), and the order is destroyed. And you can remove and add objects from/ in the middle of the list.

If I wanted to change the order of my elements in an array, I’d have to make some effort. It doesn’t happen accidentally with a single line of code. I cannot change the number of “slots”.

Is this what you wanted to know?

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms