static void Main() { // The following code is OK because Friend // inherits PhoneNumber. PhoneList <Friend> plist = new PhoneList <Friend>(); plist.Add(new Friend("Tom", "555-1234", true)); plist.Add(new Friend("Gary", "555-6756", true)); plist.Add(new Friend("Matt", "555-9254", false)); try { // Find the number of a friend given a name. Friend frnd = plist.FindByName("Gary"); Console.Write(frnd.Name + ": " + frnd.Number); if (frnd.IsWorkNumber) { Console.WriteLine(" (work)"); } else { Console.WriteLine(); } } catch (NotFoundException) { Console.WriteLine("Not Found"); } Console.WriteLine(); // The following code is also OK because Supplier // inherits PhoneNumber. PhoneList <Supplier> plist2 = new PhoneList <Supplier>(); plist2.Add(new Supplier("Global Hardware", "555-8834")); plist2.Add(new Supplier("Computer Warehouse", "555-9256")); plist2.Add(new Supplier("NetworkCity", "555-2564")); try { // Find the name of a supplier given a number. Supplier sp = plist2.FindByNumber("555-2564"); Console.WriteLine(sp.Name + ": " + sp.Number); } catch (NotFoundException) { Console.WriteLine("Not Found"); } // The following declaration is invalid because EmailFriend // does NOT inherit PhoneNumber. // PhoneList<EmailFriend> plist3 = // new PhoneList<EmailFriend>(); // Error! }
static void Main() { // The Following code is Ok because Friend // implements IPhoneNumber PhoneList <Friend> pList = new PhoneList <Friend>(); pList.Add(new Friend("Tom", "555-1234", true)); pList.Add(new Friend("Gary", "123-1234", true)); pList.Add(new Friend("Dick", "333-1234", true)); pList.Add(new Friend("Harry", "666-1234", true)); try { // Find the number of a friend given a name Friend frnd = pList.FindByName("Tom"); Console.Write(frnd.Name + ":" + frnd.Number); if (friend.IsWorkNumber) { Console.WriteLine(" (work)"); } else { Console.WriteLine(); } }catch (NotFoundException) { Console.WriteLine("Not Found"); } Console.WriteLine(); // The Following code is also Ok beacause Supplier implements IPhoneNumber PhoneList <Supplier> pList2 = new PhoneList <Supplier>(); pList2.Add(new Supplier("Mr. A", "111-1111")); pList2.Add(new Supplier("Mr. B", "111-4444")); pList2.Add(new Supplier("Mr. C", "111-3333")); pList2.Add(new Supplier("Mr. D", "111-2222")); try { // Find the Name of the Supplier given a number Supplier sp = pList2.FindByNumber(); Console.WriteLine(sp.Name + ":" + sp.Number); } catch (NotFoundException) { Console.WriteLine(Not Found); } // The Following Declaration is invalid because EmailFriend Does not // Implement IPhoneNumber // PhoneList<EmailFriend> pList3 = new PhoneList<EmailFriend>(); // Error }
static void Main() { // The Following code is Ok because Friend // implements IPhoneNumber PhoneList<Friend> pList = new PhoneList<Friend>(); pList.Add(new Friend("Tom", "555-1234", true)); pList.Add(new Friend("Gary", "123-1234", true)); pList.Add(new Friend("Dick", "333-1234", true)); pList.Add(new Friend("Harry", "666-1234", true)); try { // Find the number of a friend given a name Friend frnd = pList.FindByName("Tom"); Console.Write(frnd.Name + ":" + frnd.Number); if(friend.IsWorkNumber) Console.WriteLine(" (work)"); else Console.WriteLine(); }catch(NotFoundException) { Console.WriteLine("Not Found"); } Console.WriteLine(); // The Following code is also Ok beacause Supplier implements IPhoneNumber PhoneList<Supplier> pList2 = new PhoneList<Supplier>(); pList2.Add(new Supplier("Mr. A", "111-1111")); pList2.Add(new Supplier("Mr. B", "111-4444")); pList2.Add(new Supplier("Mr. C", "111-3333")); pList2.Add(new Supplier("Mr. D", "111-2222")); try { // Find the Name of the Supplier given a number Supplier sp = pList2.FindByNumber(); Console.WriteLine(sp.Name + ":" + sp.Number); } catch(NotFoundException) { Console.WriteLine(Not Found); } // The Following Declaration is invalid because EmailFriend Does not // Implement IPhoneNumber // PhoneList<EmailFriend> pList3 = new PhoneList<EmailFriend>(); // Error }
async void Init() { var soapClient = new Bubble.ContactsSoapClient(); IEnumerable <Person> persons; IEnumerable <Email> ems; IEnumerable <Address> ads; IEnumerable <Phone> phs; persons = await soapClient.GetPeopleAsync(); foreach (var dude in persons) { ContactList.Add(dude); } ems = await soapClient.GetEmailsAsync(); foreach (var e in ems) { EmailList.Add(e); } ads = await soapClient.GetAddressesAsync(); foreach (var a in ads) { AddressList.Add(a); } phs = await soapClient.GetPhonesAsync(); foreach (var p in phs) { PhoneList.Add(p); } foreach (var dude in ContactList) { foreach (var e in EmailList) { if (dude.PID == e.PersonID) { dude.elist.Add(e); } } foreach (var a in AddressList) { if (dude.PID == a.PersonID) { dude.alist.Add(a); } } foreach (var p in PhoneList) { if (dude.PID == p.PersonID) { dude.plist.Add(p); } } } }
public WebDialerOptions() { InitializeComponent(); phoneList = new PhoneList(Globals.WebDialerAddIn.phoneList); if (phoneList.Count == 0) phoneList.Add(newPhone()); }
static void Main() { PhoneList <FriendNumber> pList = new PhoneList <FriendNumber>(); pList.Add(new FriendNumber("Ivan", "891277777777", false)); pList.Add(new FriendNumber("Paul", "891275675677", true)); pList.Add(new FriendNumber("Tom", "891745645777", false)); try { FriendNumber frnd = pList.FindByName("Ivan"); Console.WriteLine(frnd.Name + " " + frnd.Number); if (frnd.isWorkNumber) { Console.WriteLine(" (рабочий)"); } else { Console.WriteLine(); } } catch (NotFoundException) { Console.WriteLine("Not found"); } Console.WriteLine(); PhoneList <Supplier> pList2 = new PhoneList <Supplier>(); pList2.Add(new Supplier("Ivan", "891277777777")); pList2.Add(new Supplier("Paul", "891275675677")); pList2.Add(new Supplier("Tom", "891745645777")); try { Supplier frnd2 = pList2.FindByNumber("891275675677"); Console.WriteLine(frnd2.Name + " " + frnd2.Number); } catch (NotFoundException) { Console.WriteLine("Not found"); } }
public static void Main1() { PhoneList <Friends> plist = new PhoneList <Friends>(); plist.Add(new Friends("Tom", "555-1234", true)); plist.Add(new Friends("Garry", "555-6756", true)); plist.Add(new Friends("Matt", "555-9254", false)); try { Friends frnd = plist.FindByName("Garry"); System.Console.Write(frnd.Name + " " + frnd.Number); if (frnd.IsWorkNumber) { Console.WriteLine(" (рабочий)"); } else { System.Console.WriteLine(); } } catch (NotFoundException) { System.Console.WriteLine("Не найдено."); } System.Console.WriteLine(); PhoneList <Supplier> plist2 = new PhoneList <Supplier>(); plist2.Add(new Supplier("Company Global Hardware", "555-8834")); plist2.Add(new Supplier("Agency Computer Warehouse", "555-9256")); plist2.Add(new Supplier("Company NetworkCity", "555-2564")); try { Supplier sp = plist2.FindByNumber("555-2564"); System.Console.WriteLine(sp.Name + " " + sp.Number); } catch (NotFoundException) { System.Console.WriteLine("Не найдено."); } }