gpt4 book ai didi

c# - int[] 是引用类型还是值类型?

转载 作者:IT王子 更新时间:2023-10-29 03:34:36 26 4
gpt4 key购买 nike

我知道 int 是值类型,但什么是值类型数组?引用类型?值类型?我想将一个数组传递给一个函数来检查一些东西。我应该只传递数组,因为它只会传递它的引用,还是应该将它作为 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

关于c# - int[] 是引用类型还是值类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1533757/

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