Array and List are elements present in most programming languages and are a very useful tool when you need to build a set of objects of the same type.

Array

To declare an array in c#, add the square brackets after the type definition, and give a name to your variable.

when you declare an array, you are building a set of contiguous boxes ready to host a variable of the declared type for each of its boxes. In fact when you declare an array you allocate a precise space of memory.

It is also possible to create multidimensional arrays, just put a comma inside the brackets.

List

For lists to be declared ask to explicitly use the keyword List followed by the type in angle brackets and its name.

Lists are easier to manipulate, we can add elements at will. They don’t need a contiguous space between their elements because each element of a list is composed of the value of its variable and the element that points to the next value in the list.

Conclusion

In conclusion, they are two tools that you have to use according to the situation. Array memory is static and continuous. List memory is dynamic and random. Users do not need to keep track of the next memory with arrays. With lists, the user needs to keep track of the next location.

In Unity, both can be serialized and modified in the Inspector. And we can also create Arrays and Lists from classes we create as well as from primitive types.

project manager by day, unity developer by night