As I know string is a referenced type and when you send a referenced type to a function, if you change its value, the value of the original object will change, but why when I call change function the original string remains unchanged. But when I have an object of a class and send it to a function, it original value will change. Here is an example:
static void Main(string[] args)
{
string x = "Hi";
Change(x);
Console.WriteLine(x);
var y = new Test();
y.Str = "Hi";
Change(y);
Console.WriteLine(y.Str);
Console.ReadKey();
}
static void Change(string str)
{
str = "Test";
}
static void Change(Test x)
{
x.Str = "Test";
}
The output is "Hi" instead of "Test" for string, but for Test object it is "Test"