今天我学习了值类型和引用类型。
我对下面的代码示例有一个疑问:
class Program
{
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
FunctionSB(sb);
Console.WriteLine(sb); //sb updated
customer c = new customer();
FunctionClass(c);
Console.WriteLine(c.s);//updated class value
String str = "";
FuntionString(str);
Console.WriteLine(str);//
}
private static void FunctionSB(StringBuilder sb)
{
sb.Append("sb updated");
}
private static void FunctionClass(customer c)
{
c.s = "updated class value ";
}
static void FuntionString(String str)
{
str = "updated value";
}
}
class customer
{
public string s;
}
这里更新了字符串生成器值和类成员变量值,但是为什么FuntionString(str);
不更新str
值呢?(为什么不作为参考传递?)