为int []引用类型还是值类型? [英] Is int[] a reference type or a value type?

查看:301
本文介绍了为int []引用类型还是值类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道一个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?

解决方案

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

这篇关于为int []引用类型还是值类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆