First, consider the second and third questions:
and if it really affects the speed of access and retrieval of data from memory?
and if true, what makes the array a little faster than the list?
In .NET, there is only one type of "native" collection (with .NET, I mean CLR, so the runtime): an array (technically, if you consider the string type to be a collection type, then there are two types of collection types :-)) ( technically part 2: not all arrays, which, in your opinion, are arrays, are βnativeβ arrays ... Only arrays based on monomeric 0 are βnativeβ arrays. There are no arrays of type T[,] , but arrays where the first element has no index 0, are not). Another collection is built on it (except LinkedList<> ). If you look at List<T> using IlSpy , you will see that there is T[] in the database with an added int for Count ( T[].Length is Capacity ). Obviously, the array is a little faster than List<T> , because to use it you have one less indirectness (you are accessing the array directly, not accessing the array that accesses the list).
Let's look at the first question:
Does it contain elements sequentially located in an array with a bunch, or each element is randomly located in different places?
Based on the array inside, it is clear that List<> remembers its elements, such as an array, therefore in an adjacent memory block (but keep in mind that with List<SomeObject> , where SomeObject is a reference type, the list is a list of links , not objects , so links are placed in a continuous memory block (we will ignore this using advanced computer memory management, the word "continuous memory block" is not exact ", it would be better to say" adjacent address block "))
(yes, even Dictionary<> and HashSet<> built on top of arrays. Conversely, a tree-like collection can be built without using an array, since it looks more like a LinkedList )
Additional information: in CIL there are four groups of instructions (an intermediate language used in compiled .NET programs) that are used with native arrays:
Newarr
Ldelem and the Ldelem_* family
Stelem and the Stelem_* family Stelem_*
ReadOnly (don't ask me about usage, I don't know, and the documentation is not clear)
if you look at OpCodes.Newarr , you will see this comment in the XML documentation:
// Summary: // Pushes an object reference to a new zero-based, one-dimensional array whose // elements are of a specific type onto the evaluation stack.