How parameter by reference/value works in C#
问题 I have this sample code: public class MyClass { public int Value { get; set; } } class Program { public static void Foo(MyClass v) { v.Value = 2; v = new MyClass(); v.Value = 3; } static void Main(string[] args) { var m = new MyClass(); m.Value = 1; Foo(m); Console.Write(m.Value); Console.ReadLine(); } } I would like to understand why the output is 2 and not 3, could you please give me some clear explanation? Thanks 回答1: I will go through with you, step by step via the debugger and we will