加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 引用类型和引用之间的区别

发布时间:2020-12-16 02:01:00 所属栏目:百科 来源:网络整理
导读:我正在阅读Eric Lippert的博客: The truth about Value types 在此,他提到开幕式中有三种价值观: 值类型的实例 引用类型的实例 参考文献 It is incomplete. What about references? References are neither value types nor instances of reference types,
我正在阅读Eric Lippert的博客: The truth about Value types

在此,他提到开幕式中有三种价值观:

>值类型的实例
>引用类型的实例
>参考文献

It is incomplete. What about references? References are neither value types nor instances of reference types,but they are values..

因此,在以下示例中:

int i = 10;
string s = "Hello"

第一个是值类型的实例,第二个是引用类型的实例.那么,第三种类型是什么,参考文献以及我们如何获得它?

解决方法

So,what is the third type,References and how do we obtain that?

变量s是保存参考值的变量.此值是对内存中字符串(值为“Hello”)的引用.

为了使这一点更清楚,请说:

string s1 = "Hello";
 string s2 = s1;

在这种情况下,s1和s2都是变量,每个变量都是对同一引用类型实例(字符串)的引用.这里只涉及一个实际的字符串实例(引用类型),但有两个对该实例的引用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读