Evaluating typeof(Object[,][]).Name
gives Object[][,]
Similarly, typeof(Object[][,]).Name
gives Object[,][]
Seems like the comma is moving for no reason.
What gives?
Mixing ragged and rectangular arrays is a recipe for insanity. Your intuition about what a given type notation means is almost always wrong, or, at least, mine is.
Read my article on the subject and see if that helps you understand what is going on here:
http://blogs.msdn.com/b/ericlippert/archive/2009/08/17/arrays-of-arrays.aspx
Basically: C# and reflection notate mixed ragged/rectangular arrays in two different ways, each for their own reasons.
Leaving aside the purpose for which you might want to declare such exotic array, it looks like the way the reflection produces the name of an array is recursive: first, it produces the name of array's element type, and then appends square brackets with the appropriate number of commas.
Object[,][]
is a 2D array of 1D arrays; the element type of the 2D array is Object[]
, so the overall result is "Object[]"+"[,]"
.
Here is another illustration of the way the algorithm works:
typeof(Object[][,][,,][,,,][,,,,]).Name
is
Object[,,,,][,,,][,,][,][]
I don't see a reason behind it other than the efficiency of implementation: as long as it is consistent, it does not matter if the syntax matches C# or not. After all, C# is not the only language in the .NET universe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With