int[] array1 = new[] { 1, 2, 3 };
int[] array2 = (int[])array1.Clone();
array2[0] = 9;
Debug.Assert(array1[0] != array2[0]);
This works fine. Clone()
does a shallow copy, but the array types are value types, so they get cloned too.
My question is whether this is explicit in the language spec, or whether this is just an artifact of the current implementation?
My doubt is due to System.Array
supporting value types "invisibly" behind the scenes via run-time generics . Looking at the public methods you would expect value types to be boxed.