public static void Main() { IDList <Engineer> plist = new IDList <Engineer>(); plist.add(new Engineer("T", "1")); plist.add(new Engineer("G", "6")); plist.add(new Engineer("M", "9")); try { Engineer frnd = plist.findByName("G"); Console.Write(frnd.Name + ": " + frnd.Number); } catch (NotFoundException) { Console.WriteLine("Not Found"); } Console.WriteLine(); IDList <Manager> plist2 = new IDList <Manager>(); plist2.add(new Manager("H", "8")); plist2.add(new Manager("C", "2")); plist2.add(new Manager("N", "4")); try { Manager sp = plist2.findByNumber("4"); Console.WriteLine(sp.Name + ": " + sp.Number); } catch (NotFoundException) { Console.WriteLine("Not Found"); } // The following declaration is invalid // because Guest does NOT implement IUserID. // IDList<Guest> plist3 = new IDList<Guest>(); // Error! }
public static void Main() { IDList <Employee> plist = new IDList <Employee>(); plist.add(new Employee("T", "1")); plist.add(new Employee("G", "6")); plist.add(new Employee("M", "5")); try { Employee frnd = plist.findByName("T"); Console.Write(frnd.Name + ": " + frnd.Number); } catch (NotFoundException) { Console.WriteLine("Not Found"); } Console.WriteLine(); IDList <Manager> plist2 = new IDList <Manager>(); plist2.add(new Manager("G", "8")); plist2.add(new Manager("C", "9")); plist2.add(new Manager("N", "2")); try { Manager sp = plist2.findByNumber("8"); Console.WriteLine(sp.Name + ": " + sp.Number); } catch (NotFoundException) { Console.WriteLine("Not Found"); } }