字符串是引用类型..它是引用类型吗? [英] string is a reference type ..is it reference type?

查看:160
本文介绍了字符串是引用类型..它是引用类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将字符串作为参数传递给函数,则它将作为引用传递.因为它是引用类型.

但是如果我在函数中更改字符串的值,则它不会更改,因为它是不可变的(我得到了这样的答案)...

所以通常当我们想要将字符串作为参数传递时,我们永远都不想将其作为引用传递..因为它已经是一个引用...

但是如果我尝试将字符串作为"ref"发送,则该值将被更改...

它是如何工作的..因为字符串已经是引用??

if i am passing a string to a function as parameter then it is passing as reference..Because it is reference type.

But if i am changing the value of the string in the function then it is not getting changed, because it is immutable(i got the answer like this)...

so normally when we want to pass a string as param, we never want to pass as reference..because it is already a reference...

but if i am trying to send the string as ''ref'' then the value is getting changed...

How it is working.. because string is already a reference ??

推荐答案



此链接对您有很大帮助
http://msdn.microsoft.com/en-us/library/s6938f28 (v = vs.80).aspx [
Hi,

This link will Help u lot
http://msdn.microsoft.com/en-us/library/s6938f28(v=vs.80).aspx[^]

best Luck
happy Coding


C#为此具有out(或ref,具体取决于您的需求)关键字,请参见: [
C# has out (or ref, depending on your needs) keyword for that, see: "out parameter modifier (C# Reference)"[^].


这篇关于字符串是引用类型..它是引用类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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