Today I learned about value types and reference types.
I am having one doubt in the code sample below:
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;
}
Here the string builder value and class member variable value is updated, but why is FuntionString(str);
not updating the str
value? (Why is it not passed as a reference?)