我将字符串变量传递给方法.我知道字符串是引用类型,但我在方法中分配的值丢失了.
public static void TestMethod(string myString)
{
myString = "world";
}
static void Main(string[] args)
{
string s = "hello";
Console.WriteLine(s); // output is "hello"
TestMethod(s);
Console.WriteLine(s); // output is also "hello" not "world" !?
}
Run Code Online (Sandbox Code Playgroud)
无论如何,例如,数组不会发生这种情况.有人可以解释为什么可能是原因吗?