static void Main(string[] args) { //不使用new来生成结构,其内部成员将初始化为 Family newFamily; newFamily.name = "nanxiaodong"; newFamily.sex = true; Console.WriteLine(newFamily.name); //以new来生成结构,调用带参数的构造器 Family myFamily = new Family("nxd Family",25,true,"China",new Person("nxd",26)); Person person = new Person(); person.Name = "Nxd"; //按值传递参数 ShowFamily(myFamily); //按引用传递参数 ShowPerson(person); Console.WriteLine("***************************"); Console.WriteLine("I'm {0}",myFamily.name); Console.WriteLine("I'm {0}", person.Name); myFamily.GetSex(); myFamily.ShowPerson(); Console.WriteLine("***************************"); Console.WriteLine(myFamily.ToString()); Console.ReadKey(); }
public static void ShowFamily(Family family) { family.name = "nxd"; Console.WriteLine("This is {0}",family.name); }