static void Main(string[] args) { int i = 8; Console.WriteLine("i="+i); //值类型为复制副本传递,调用方在副本上操作,不影响传递参数。 ChangeValue(i); Console.WriteLine("change i="+i); var s = i.ToString(); //字符串是不可变的 ChangeValue(s); Console.WriteLine("string s="+s); Test test = new Test(); test.Sex = s; Console.WriteLine("pre test.Sex=" + test.Sex); //引用类型 传递为指针地址 ChangeValue(test); Console.WriteLine("change test.Sex=" + test.Sex); //装箱 out 关键字会导致参数通过引用来传递 ChangeValue(out i); Console.WriteLine("out i=" + i); Console.ReadKey(); } //重载:方法签名不一样(参数类型及参数个数) public static void ChangeValue(int v) { v = 88; } //字符串可变 public static void ChangeValue(string v) { v = "88"; } public static void ChangeValue(Test test) { test.Sex = "88"; } //out:以引用方式传递指针地址 public static void ChangeValue(out int v) { v = 88; } //编译报错:方法签名一样,而返回类型不一致并不是重载 //public static string ChangeValue(string v) //{ // v = "88"; // return v; //} class Test { private string sex; public string Sex { get { return this.sex; } set { this.sex = value; } } }