C#中的引用和值类型 [英] Reference and value type in C#
本文介绍了C#中的引用和值类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
c中的参考类型和价值类型是什么?
我尝试了什么:
c#中的引用类型和值类型是什么?
解决方案
值类型
>将数据保存在自己的内存位置
>存储在堆栈中。请记住这样的V a lue - St a ck
>内置数据类型,如int,byte,是值类型。除(字符串)
>如果希望更快地访问数据,请使用此选项。但其范围有限
参考类型
>指向其他内存位置的指针
>存储在堆上。请记住这样的R e ference - h e ap
>用户定义的是ref。防爆。类,数组,字符串(即使是内置的)
>如果要共享数据,请使用此功能。
MSDN :价值类型和参考类型 [ ^ ]。
what is reference type and value type in c#
What I have tried:
what is reference type and value type in c#
解决方案
Value Type
> Holds data in its own memory location
> Stored in Stack. Remember like this Value - Stack
> inbuilt data types such as int, byte, are value type. Except (string)
> When you want data to get accessed faster use this. however its scope is limited
Reference Type
> Pointer to other memory location
> Stored on heap. Remember like this Reference - heap
> User defined are ref. Ex. classes, arrays, string(even though inbuilt)
> When you want to share data, use this.
MSDN:Value Types and Reference Types[^].
这篇关于C#中的引用和值类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文