Why is an array of ints not an array of objects? And why can a pattern of type 'object[]' not be used for 'int[]'?
1 is object
True
new int[10] is object
True
new int[10] is object[] // Why?
False
(Array)new int[10] is object[]
False
(Array)new object[10] is object[]
True
new object() is object
True
new object[10] is object
True
new object[10] is object[]
True
int[] arr = new int[10];
// Why the compilation error?
// error CS8121: An expression of type 'int[]' cannot be handled by a pattern of type 'object[]'
if (arr is object[] objArr)
Console.WriteLine(objArr);
// And this works:
if ((Array)arr is object[] objArr)
Console.WriteLine(objArr);
I came across this line in the source code: https://source.dot.net/#System.Private.CoreLib/Array.cs,1644
.NET version is 3.1.10 (same on mono 6.4.0).