static void Main() { //GenericList<string> test = new GenericList<string>(); //test.AddElement("Testing"); //test.AddElement("string"); //Console.WriteLine(test.ToString()); //before inserting a new element //test.InsertAtIndex(0, "sf"); //Console.WriteLine(test.ToString()); //after inserting a new element //var testAccessByIndex = test.AccessByIndex(1); //Console.WriteLine("I am the element at index 1 = {0}", testAccessByIndex); GenericList<double> anotherTest = new GenericList<double>(); anotherTest.AddElement(1); anotherTest.AddElement(2); anotherTest.AddElement(3); anotherTest.AddElement(4); Console.WriteLine("Numbers = {0}", anotherTest.ToString()); var minElement = anotherTest.Min(); Console.WriteLine("MIN element is {0}", minElement); var maxElement = anotherTest.Max(); Console.WriteLine("MAX element is {0}", maxElement); Console.WriteLine("Element[1] using indexer = {0}", anotherTest[1]); Console.WriteLine("Element AccessByIndex(1) = {0}", anotherTest.AccessByIndex(1)); anotherTest.RemoveByIndex(1); Console.WriteLine("Removed element[1], result = {0}", anotherTest.ToString()); anotherTest.InsertAtIndex(1, 5); Console.WriteLine("Insert 5 at index[1],result = {0}",anotherTest.ToString()); anotherTest.ClearList(); Console.WriteLine("Elements ClearList() = {0}", anotherTest.ToString()); Console.WriteLine("Check if list contains 0: {0}",anotherTest.FindByValue(0)); }
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(); }
private static void Main() { GenericList<string> list = new GenericList<string>(); //adding an element list.Add("0 - primeren"); list.Add("1 - listttt"); list.Add("2 - asfsdfsdfsdfd"); //accessing element by index string s = list.AccessByIndex(1); Console.WriteLine(s); Console.WriteLine("------------------"); //removing element by index list.RemoveAt(1); list.Print(); Console.WriteLine("----------------"); //inserting element at given position list.InsertAt("inserttttt", 2); list.Print(); Console.WriteLine("-----------------"); //clearing the list list.Clear(); //check if the list contains a value list.Add("edno"); list.Add("dve"); list.Add("tri"); bool b = list.Contains("dve"); Console.WriteLine(b); Console.WriteLine("---------------"); //print the entire list list.Print(); Console.WriteLine("----------------"); //auto-grow //GenericList<string> list3 = new GenericList<string>() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17" }; //list3.Print(); //Console.WriteLine("-------------------"); GenericList<int> list4 = new GenericList<int> {1, 2, -3, 4, 50, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; list4.Print(); Console.WriteLine("--------"); //min var min = list4.Min(); Console.WriteLine(min); //max var max = list4.Max(); Console.WriteLine(max); Console.WriteLine("------------"); //Problem 4 - Generic List Version Type type = typeof (GenericList<>); object[] allAttributes = type.GetCustomAttributes(false); foreach (VersionAttribute attr in allAttributes) { Console.WriteLine("Version: {0}", attr.Version); } }