O'Reilly logo
  • Ismael Lanchas thinks this is interesting:

An array can contain value-type or reference-type elements. Value type elements are stored in place in the array, so an array of three long integers (each 8 bytes) will occupy 24 bytes of contiguous memory. A reference type element, however, occupies only as much space in the array as a reference (4 bytes in a 32-bit environment or 8 bytes in a 64-bit environment). Figure 7-2 illustrates the effect, in memory, of the following program:

StringBuilder[] builders = new StringBuilder [5];
builders [0] = new StringBuilder ("builder1");
builders [1] = new StringBuilder ("builder2");
builders [2] = new StringBuilder ("builder3");

long[] numbers = new long [3];
numbers [0] = 12345;
numbers [...
            
        
			

From

Cover of C# 6.0 in a Nutshell, 6th Edition

Note

Explicación clara de cómo se almacenan las colecciones en memoria con tipos por referencia o primitivas.