static void Main() { GenericList <int> list = new GenericList <int>(); list.AddItem(5); list.AddItem(3); Console.WriteLine("{2,-20} Capacity = {0}; Count = {1}", list.Capacity, list.Count, list); list.AddItem(7); list.AddItem(1); Console.WriteLine("{2,-20} Capacity = {0}; Count = {1}", list.Capacity, list.Count, list); list.AddItem(2); Console.WriteLine("{2,-20} Capacity = {0}; Count = {1}", list.Capacity, list.Count, list); Console.WriteLine(); Console.WriteLine(list); list.InsertItem(3, 34); Console.WriteLine("{2,-20} Capacity = {0}; Count = {1}", list.Capacity, list.Count, list); list.RemoveItem(2); Console.WriteLine("{2,-20} Capacity = {0}; Count = {1}", list.Capacity, list.Count, list); Console.WriteLine("Min element in list: {0}", list.Min()); Console.WriteLine("Max element in list: {0}", list.Max()); list.Clear(); // give error because is not IComparable interface //GenericList<NotIComparableClass> listOfNotIComparableClass = new GenericList<NotIComparableClass>(); }
public static void RunGenericListTest() { GenericList <School.Student> GenericListOfStudents = new GenericList <School.Student>(10); //ADD ITEMS: GenericListOfStudents.AddItem(new School.Student("Bill")); GenericListOfStudents.AddItem(new School.Student("Bob")); GenericListOfStudents.AddItem(new School.Student("Jim")); GenericListOfStudents.AddItem(new School.Student("Horace")); GenericListOfStudents.AddItem(new School.Student("Mark")); GenericListOfStudents.AddItem(new School.Student("James")); GenericListOfStudents.AddItem(new School.Student("Phill")); GenericListOfStudents.AddItem(new School.Student("Peter")); GenericListOfStudents.AddItem(new School.Student("Keith")); GenericListOfStudents.AddItem(new School.Student("Wayne")); Console.WriteLine(); //AccessByIndex Console.WriteLine(GenericListOfStudents.AccessByIndex(3).ToString());//should be 'horace' -YES Console.WriteLine(); //RemoveByIndex GenericListOfStudents.RemoveByIndex(3); GenericListOfStudents.PrintAllItems(); Console.WriteLine(); //InsertAtPosition GenericListOfStudents.InsertAtPosition(new School.Student("FELLOW STUDENT"), 3); GenericListOfStudents.PrintAllItems(); Console.WriteLine(); //SearchByValue GenericListOfStudents.SearchByValue(GenericListOfStudents.someList[0]); Console.WriteLine(); //ToString OverLoad: Console.WriteLine(GenericListOfStudents.ToString()); Console.WriteLine(); ////ClearList(); //GenericListOfStudents.ClearList(); //GenericListOfStudents.PrintAllItems(); //Console.WriteLine(); //Add items past array size, try to increase size mof array to accomodate: GenericListOfStudents.AddItem(new School.Student("Bill")); GenericListOfStudents.AddItem(new School.Student("Bob")); GenericListOfStudents.AddItem(new School.Student("Jim")); GenericListOfStudents.AddItem(new School.Student("Horace")); Console.WriteLine(); GenericListOfStudents.PrintAllItems(); Console.WriteLine(); GenericListOfStudents.AddItem(new School.Student("Bob")); GenericListOfStudents.AddItem(new School.Student("Jim")); Console.WriteLine(); GenericListOfStudents.PrintAllItems(); Console.WriteLine(); //ToString OverLoad: Console.WriteLine(GenericListOfStudents.ToString()); Console.WriteLine(); Console.WriteLine(); }