int和int []有什么区别 [英] What's the differense between int and int[]

查看:135
本文介绍了int和int []有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假定此功能:

Assume this function:

private void Changing(int[] is, int i)<br />{<br />    is[0] = 100;<br />    i = 100;<br />}<br />


当我调用更改Main"时:


When I call Changing in Main:

<br />static void Main()<br />{<br />    int[] is = {0, 1, 2, 3, 4};<br />    int i = 0;<br />    Console.WriteLine(i); // Writes 0<br />    Console.WriteLine(is[0]); // Writes 0<br /><br />    Changing(is, i);<br />    Console.WriteLine(i); // Still 0.<br />    Console.WriteLine(is[0]); // Prints 100!<br />}<br />



已更改,但 i 没有,为什么?



is changed but i didn''t, why?

推荐答案

C#中的数组属于引用类型的类别.像任何其他引用类型一样,数组对象引用在堆上分配的内存空间.

如果您想深入了解,请去Google咨询Value Type vs Reference Type.

Arrays in C# fall in the category of reference types. Like any other reference type, an array object refers to a memory space allocated on the heap.

If you want to deep knowledge then go to Google for Value Type vs Reference Type.


这篇关于int和int []有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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