治什么样的内存语义在C#中数组赋值? [英] What kind of memory semantics govern array assignment in c#?

查看:100
本文介绍了治什么样的内存语义在C#中数组赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下内容:字节[] SDATA; 并声明为专用字节[] construct_command()

Given the following: byte[] sData; and a function declared as private byte[] construct_command()

如果我然后分配结果的 construct_command() SDATA
将SDATA只是指向的内容是什么从函数返回或会的一些空间在存储器中alloctaed为SDATA和函数的结果的内容被复制到什么?

if I were to then assign the result of construct_command() to sData would sData just point to the contents of what's returned from the function or would some space be alloctaed for sData in memory and the contents of the result of the function be copied into it?

推荐答案

假设SDATA是一个局部变量,它会住在栈,它会参考以该方法返回数组。该方法不返回数组本身,但对数组的引用的内容。

Assuming sData is a local variable, it will live in the stack and it will refer to the array returned by the method. The method does not return the contents of the array itself, but a reference to the array.

在.NET中,数组是第一类对象和所有数组类型变量其实引用。

In .net, arrays are first class objects and all array-type variables are in fact references.

这篇关于治什么样的内存语义在C#中数组赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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