Necesita matrices para administrar su colección de estructuras mutables , por supuesto, y qué haríamos sin ellas.
struct EvilMutableStruct { public double X; } // don't do this
EvilMutableStruct[] myArray = new EvilMutableStruct[1];
myArray[0] = new EvilMutableStruct()
myArray[0].X = 1; // works, this modifies the original struct
List<EvilMutableStruct> myList = new List<EvilMutableStruct>();
myList.Add(new EvilMutableStruct());
myList[0].X = 1; // does not work, the List will return a *copy* of the struct
(tenga en cuenta que puede haber algunos casos en los que sea deseable una matriz de estructuras mutables, pero generalmente este comportamiento diferente de estructuras mutables dentro de las matrices frente a otras colecciones es una fuente de errores que deben evitarse)
Más en serio, necesita una matriz si desea pasar un elemento por referencia . es decir
Interlocked.Increment(ref myArray[i]); // works
Interlocked.Increment(ref myList[i]); // does not work, you can't pass a property by reference
Eso puede ser útil para el código seguro de subprocesos sin bloqueo.
Necesita una matriz si desea inicializar de manera rápida y eficiente su colección de tamaño fijo con el valor predeterminado .
double[] myArray = new double[1000]; // contains 1000 '0' values
// without further initialisation
List<double> myList = new List<double>(1000) // internally contains 1000 '0' values,
// since List uses an array as backing storage,
// but you cannot access those
for (int i =0; i<1000; i++) myList.Add(0); // slow and inelegant
(tenga en cuenta que sería posible implementar un constructor para List que haga lo mismo, es solo que C # no ofrece esta función)
necesita una matriz si quiere copiar eficientemente partes de la colección
Array.Copy(array1, index1, array2, index2, length) // can't get any faster than this
double[,] array2d = new double[10,100];
double[] arraySerialized = new double[10*100];
Array.Copy(array2d, 0, arraySerialized, 0, arraySerialized.Length);
// even works for different dimensions
(de nuevo, esto es algo que también podría implementarse para List, pero esta característica no existe en c #)
List<T>