//找出年龄最小的对象 private static Wife GetYoungestWife(Wife[] wifeArray) { Wife GetYoungestWife = wifeArray[0]; for (int i = 1; i < wifeArray.Length; i++) { if (wifeArray[i].Age < GetYoungestWife.Age) { GetYoungestWife = wifeArray[i]; } } return(GetYoungestWife); }
static void MainWife() { //声明Wife类型的引用 Wife wife_1; //指向Wife类型的对象(实例化) wife_1 = new Wife(); wife_1.SetName("UMP45"); wife_1.SetAge(16); Console.WriteLine(wife_1.GetName()); Console.WriteLine(wife_1.GetAge()); Wife wife_2 = new Wife(); wife_2.Name = "Tac50"; wife_2.Age = 17; Console.WriteLine(wife_2.Name); Console.WriteLine(wife_2.Age); Wife wife_3 = new Wife("qbz95", 26); Console.WriteLine(wife_3.Name); Console.WriteLine(wife_3.Age); Wife wife_4 = new Wife("01", 23); Wife wife_5 = new Wife("34", 20); Wife wife_6 = new Wife("03", 19); Wife wife_7 = new Wife("04", 28); Wife wife_8 = new Wife("05", 36); Wife wife_9 = new Wife("06", 40); Wife[] wifeArray = new Wife[] { wife_1, wife_2, wife_3, wife_4, wife_5, wife_6, wife_7, wife_8, wife_9 }; Console.WriteLine("young : " + GetYoungestWife(wifeArray).Name); }