为int []引用类型还是值类型?类型、int

2023-09-02 21:22:05 作者:沒有你的那種空洞

我知道一个int是值类型,但什么是值类型的数组?引用类型?值类型?我想一个数组传递给一个函数来检查一番。如果我只是通过阵列,因为它会只是通过它的引用,或者我应该把它作为参考?

解决方案   

数组是机制,允许你   治疗几个项目作为一个单一的   采集。在Microsoft®.NET通用   语言运行时(CLR)支持   一维数组,   多维数组和锯齿   阵列(数组的数组)。所有的数组   类型隐含源自   的System.Array,它本身是衍生   从System.Object。这意味着   所有的数组总是引用类型   被分配在管理   堆,和你的应用程序的变量包含   的引用数组,而不是   数组本身。

https://msdn.microsoft.com/en-us/library/ bb985948.aspx

I know an int is a value type, but what are arrays of value types? Reference types? Value types? I want to pass an array to a function to check something. Should I just pass the array, as it will just pass the reference of it, or should I pass it as ref?

解决方案 c 中值类型和引用类型的区别

Arrays are mechanisms that allow you to treat several items as a single collection. The Microsoft® .NET Common Language Runtime (CLR) supports single-dimensional arrays, multidimensional arrays, and jagged arrays (arrays of arrays). All array types are implicitly derived from System.Array, which itself is derived from System.Object. This means that all arrays are always reference types which are allocated on the managed heap, and your app's variable contains a reference to the array and not the array itself.

https://msdn.microsoft.com/en-us/library/bb985948.aspx