Hi!A have a string variable (which is a reference type).Now I define my Method like that:void MakeFullName(string sNamePrivate){sNamePrivate+="Gates"}The calling code:string sName="Bill";MakeFullName(sName);My variable sName wasn''t changed (the same "Bill"). String is areference type and I would expectthat it will be passed by reference without defining the methodparameter as "ref". Only after defining it as "ref" I get the expectedresult ("BillGates").void MakeFullName1(ref string sNamePrivate){sNamePrivate+="Gates"}The calling code:string sName="Bill";MakeFullName1(ref sName);In the following article Jesse Liberty explicitly says, that referenceparameters are passed by reference: http://www.ondotnet.com/pub/a/dotnet...ps.html?page=2"Value types are passed to methods by value (a copy is made) whilereference types are effectively passed by reference."Does it mean, that unless I declare my paramter as "ref" my valueoutside the mehtod is never changed?Thanks for you help.Maxim 解决方案 这篇关于将引用类型作为方法参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 06:13