为什么字符串是c#中的值类型 [英] why string is value type in c#

查看:77
本文介绍了为什么字符串是c#中的值类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





字符串类是密封类。



我们正在考虑的任何类型是ref类型。



但为什么'string'类型在值类型下。



请不要tel字符串是引用类型。



问候

raja

Hi,

the string class is sealed class.

any class type we are considering is ref type.

but why 'string' type under the value type.

please dont tel string is reference type.

Regards
raja

推荐答案

请转到通过以下链接

是字符串值类型或引用类型。 [ ^ ]

在C#中,为什么String是一个行为类似于值类型的引用类型? [ ^ ]
Please go through the following links
Is string a value type or Reference type..[^]
In C#, why is String a reference type that behaves like a value type?[^]


因为字符串类型是不可变的(你不能改变内容一旦定义了该对象)。



Ex。



string str ='嗨';

str = str +'all';



在第二行,CLR创建另一个字符串类型的对象,尽管使用现有的字符串对象。
Because string type is immutable(You can't change the content of the object once it's been defined).

Ex.

string str = 'Hi';
str = str + ' all';

In second line, CLR create another object of string type, inspite of using existing string object.


String 不是值类型/参考类型它是不可变的类型



为什么字符串是不可变的,它的含义是什么? [ ^ ]

http://stacko verflow.com/questions/2365272/why-net-string-is-immutable [ ^ ]
String is not a value type/ Reference type it is an Immutable Type

Why strings are immutable and what are the implications of it?[^]
http://stackoverflow.com/questions/2365272/why-net-string-is-immutable[^]


这篇关于为什么字符串是c#中的值类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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