According to the documentation of vs: MakeArrayType()
represents one dimensional array with a lower bound of zero. MakeArrayType(1)
represents an array with a specified number of dimensions.
For example if the UnderlyingSystemType is int
the return type of MakeArrayType()
is
System.Int32[]
and the return type of MakeArrayType(1)
is System.Int32[*]
.
What is the difference between those types.
There is a subtle difference between .MakeArrayType()
and .MakeArrayType(1)
as you've seen from the type that is returned (Int32[]
versus Int32[*]
). According to the documentation for .MakeArrayType()
:
Note: The common language runtime makes a distinction between vectors (that is, one-dimensional arrays that are always zero-based) and multidimensional arrays. A vector, which always has only one dimension, is not the same as a multidimensional array that happens to have only one dimension. This method overload can only be used to create vector types, and it is the only way to create a vector type. Use the MakeArrayType(Int32) method overload to create multidimensional array types. Source
So when you call .MakeArrayType()
it returns a Vector (which is a special thing that always has one dimension). Calling .MakeArrayType(1)
makes a multi-dimensional array (not a Vector) - it just happens that it only has a single dimension.
The difference between a Vector and an Array are pretty technical but basically Vectors get special treatment by the CLR so there are additional IL instructions that work with them and that can make them more efficient. For more information about the difference between Arrays and Vectors see: http://markettorrent.com/community/7968#Vectors vs. Arrays
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