using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConTest { class ObjectOperation { public static void ChangeProperty(Student s) { s.Name = "I am"; s.Age = 23; } public static void Main() { Student s = new Student(23, "甘全福"); ChangeProperty(s); s.DisplayInfo();//输出Name:I amAge:23注意值已经改变 Console.Read(); } } class Student { public Student() { this.Age = 0; this.Name = string.Empty; } public Student(int age,string name) { this.Age = age; this.Name = name; } public int Age { get; set; } public string Name { get; set; } public void DisplayInfo() { Console.WriteLine("Name:" + this.Name + "Age:" + this.Age); } } }
转载于:https://www.cnblogs.com/ganquanfu2008/archive/2013/04/11/3013549.html