using System; class ListPets { /// /// The List Pets Program Bishop & Horspool September 2002 /// ===================== /// /// Reads in five pets and lists them again. /// Illustrates classes and references /// for building a simple linked list /// void Go() { Console.WriteLine("Type five pets with "+ "name, kind and age on separate lines"); Pet list = null; Pet p; for (int i=1; i<=5; i++) { p = new Pet(); p.GetData(); p.Previous = list; list = p; } Console.WriteLine("Your list of pets from the most recent is:"); p = list; while (p != null) { Console.WriteLine(p); p = p.Previous; } } static void Main() { new ListPets().Go(); } public class Pet { string name; string type; int age; Pet previous; public Pet Previous { get {return previous;} set {previous = value;} } public void GetData() { name = Console.ReadLine(); type = Console.ReadLine(); age = int.Parse(Console.ReadLine()); } public override string ToString() { return name+" "+type+" "+age; } } }