public bool AddAbonne(Abonne a) { if (abonnesList.Count < abonnesList.Capacity) { abonnesList.Add(a); return(true); } else { return(false); } }
static void Main(string[] args) { // Seance march 8th // Lists: // Lists are like ArrayList, with the difference being typed, // means you can only add to the list element that are of the same type. // Example // Declare a List List <int> intList = new List <int>(); // All methods in ArrayList can be found here in List for (int i = 0; i < 10; i += 1) { // print the capacity, the count and the element (visual infos each time we add) Console.WriteLine("adding element {0}, current count {1}, current capacity {2}", i, intList.Count, intList.Capacity); // adding an integer each time intList.Add(i); } // printing the list into the console foreach (int i in intList) { Console.WriteLine("{0}", i); } Console.WriteLine("\n-------------------------------------------------------\n"); // test of class Abonne, Repertoire Console.WriteLine("# TP-8 #\n"); Abonne a1 = new Abonne("name2", "+212666666666"); Abonne a2 = new Abonne("name1", "+212666666661"); Repertoire r = new Repertoire(3); if (r.AddAbonne(a1)) { Console.WriteLine("Abonne ajouter avec succes"); } else { Console.WriteLine("Repertoire est a capacite"); } if (r.AddAbonne(a2)) { Console.WriteLine("Abonne ajouter avec succes"); } else { Console.WriteLine("Repertoire est a capacite"); } r.Affichier(); if (r.GetNumero(a1.Nom) != "") { Console.WriteLine("{0} => {1}", a1.Nom, r.GetNumero(a1.Nom)); } else { Console.WriteLine("Abonne ne se trouve pas"); } Console.WriteLine("il existe {0} Abonnes dans la repertoire", r.GetNombreAbonnes()); foreach (Abonne abonne in r.GetAbonnesTries()) { Console.WriteLine("{0} => {1}", abonne.Nom, abonne.PhoneNumber); } Console.WriteLine("\n-------------------------------------------------------\n"); // test of class Chauffeur, Bus et Voyages Console.WriteLine("# Exam 2012 #\n"); showMenu(); MenuChoice menuChoice = GetChoice(); while (menuChoice != MenuChoice.Quit) { switch (menuChoice) { case MenuChoice.AddBus: AddBus(); break; case MenuChoice.AddVoyage: AddVoyage(); break; case MenuChoice.ListAllVoyage: ListAllVoyages(); break; case MenuChoice.ListAllVoyageBetweenTwoDates: foreach (var v in ListAllVoyageBetweenTwoDates()) { Console.WriteLine(v.ToString()); } break; case MenuChoice.NbrVoyageCurrentYear: Console.WriteLine("Nbr de voyages dans l'annees en cours est {0}.", NbrVoyageCurrentYear()); break; } showMenu(); menuChoice = GetChoice(); } Console.WriteLine("Good Bye!"); }