gpt4 book ai didi

c# - .MakeArrayType() 和 .MakeArrayType(1) 的区别

转载 作者:可可西里 更新时间:2023-11-01 08:21:33 29 4
gpt4 key购买 nike

根据 vs 的文档:MakeArrayType() 表示下限为零的一维数组。 MakeArrayType(1) 表示具有指定维数的数组。例如,如果 UnderlyingSystemType 是 int,则 MakeArrayType() 的返回类型是System.Int32[] 并且 MakeArrayType(1) 的返回类型是 System.Int32[*]
这些类型之间有什么区别。

最佳答案

正如您从返回的类型(Int32[ ]Int32[*])。根据 .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

因此,当您调用 .MakeArrayType() 时,它会返回一个 Vector(这是一种始终具有一维的特殊事物)。调用 .MakeArrayType(1) 生成多维数组(不是 Vector)——恰好它只有一个维度。

Vector 和 Array 之间的区别非常技术性,但基本上 Vectors 得到了 CLR 的特殊处理,因此有额外的 IL 指令可以与它们一起使用并且可以使它们更高效。有关数组和向量之间差异的更多信息,请参阅:http://markettorrent.com/community/7968#Vectors vs. Arrays

关于c# - .MakeArrayType() 和 .MakeArrayType(1) 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7057951/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com