Você precisa de matrizes para gerenciar sua coleção de estruturas mutáveis , é claro, e o que faríamos sem elas.
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
(observe que pode haver alguns casos em que uma matriz de estrutura mutável é desejável, mas geralmente esse comportamento diferente de estruturas mutáveis dentro de matrizes versus outras coleções é uma fonte de erros que devem ser evitados)
Mais a sério, você precisa de uma matriz se quiser passar um elemento por referência . ie
Interlocked.Increment(ref myArray[i]); // works
Interlocked.Increment(ref myList[i]); // does not work, you can't pass a property by reference
Isso pode ser útil para código seguro de thread sem bloqueio.
Você precisará de uma matriz se desejar, rápida e eficientemente, inicializar sua coleção de tamanho fixo com o valor padrão .
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
(observe que seria possível implementar um construtor para a lista que faz o mesmo, mas o c # não oferece esse recurso)
você precisa de uma matriz se quiser copiar com eficiência partes da coleção
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
(novamente, isso também pode ser implementado para a lista, mas esse recurso não existe no c #)
List<T>