Ejemplo n.º 1
0
        public static void Main()
        {
            GenericList<int> test1 = new GenericList<int>(3);
            GenericList<string> test2 = new GenericList<string>(3);
            GenericList<byte> test3 = new GenericList<byte>(3);
            Console.WriteLine("Testing adding");
            test1.Add(2);
            test1.Add(3);
            Console.WriteLine("Testing indexing");
            Console.WriteLine(test1[0]);
            Console.WriteLine(test1[1]);
            Console.WriteLine(test1[0] + test1[1]);
            Console.WriteLine("Testing clear");
            test1.Clear();
            //Console.WriteLine(test1[0]); // this will produce error
            test1.Add(1);
            Console.WriteLine(test1[0]);
            //Console.WriteLine(test1[1]); // this will produce error
            Console.WriteLine("Testing Remove At");
            test1.Add(2);
            test1.Add(3);

            Console.WriteLine(test1[1]);

            test1.RemoveAt(1);
            test1.Add(7);
            Console.WriteLine(test1[1]);

            Console.WriteLine("testing InsertAt");
            test1.Clear();
            test1.Add(1);
            test1.Add(2);
            test1.Add(3);
            test1.Add(4);
            test1.InsertAt(9, 2);
            Console.WriteLine(test1[1]);
            Console.WriteLine(test1[2]);
            Console.WriteLine(test1[3]);

            Console.WriteLine("testing Find");
            Console.WriteLine(test1.Find(0));
            Console.WriteLine(test1.Find(9));
            Console.WriteLine(test1.Find(4));

            Console.WriteLine("testing To String");
            Console.WriteLine(test1);

            Console.WriteLine("Testing min and max");
            Console.WriteLine(test1.Min());
            Console.WriteLine(test1.Max());

            test2.Add("asd");
            test2.Add("angry");
            test2.Add("angraer");
            Console.WriteLine(test2.Min());
            Console.WriteLine(test2.Max());
        }
Ejemplo n.º 2
0
    static void Main()
    {
        GenericList<int> list = new GenericList<int>(2);
        list.Add(1);
        list.Add(13);
        list.Add(12);

        Console.WriteLine("Generic list contains: {0}",list);

        Console.WriteLine("Second element of the list is {0}", list[2]);

        Console.WriteLine("Smallest element in the list is {0}", list.Min<int>());

        Console.WriteLine("Biggest element in the list is {0}", list.Max<int>());

        Console.Write("Please enter a value to search: ");

        int valueToSearch = int.Parse(Console.ReadLine());

        Console.WriteLine("Position: {0}", list.Find(valueToSearch));

        list.Clear();

        Console.WriteLine("List Cleared -> {0}", list);
    }
Ejemplo n.º 3
0
        static void Main()
        {
            string decorationLine = new string('-', 80);
            Console.Write(decorationLine);
            Console.WriteLine("***Creating and clearing lists of some type. Adding, removing, accessing, finding, inserting elements.***");
            Console.Write(decorationLine);

            Console.WriteLine("---Creating an empty list of strings---");
            GenericList<string> list = new GenericList<string>();
            Console.WriteLine("Empty list count: " + list.Count);
            Console.WriteLine("Empty list capacity: " + list.Capacity);

            Console.WriteLine("\n---Adding some elements to the list---");
            for (int count = 0; count < 16; count++)
            {
                list.Add("element " + (count + 1));
            }
            Console.WriteLine("The elements of the list are: " + list.ToString());
            Console.WriteLine("After adding some elements list count: " + list.Count);
            Console.WriteLine("After adding some elements list capacity: " + list.Capacity);

            Console.WriteLine("\n---Printing elements at specific indexes---");
            Console.WriteLine("Printing element with index 5: " + list[5]);
            Console.WriteLine("Printing element with index 0: " + list[0]);

            Console.WriteLine("\n---Removing some elements from the list---");
            list.RemoveAt(5);
            list.RemoveAt(0);
            list.RemoveAt(12);
            Console.WriteLine("After removing elements from the list: " + list.ToString());
            Console.WriteLine("Current list count: " + list.Count);

            Console.WriteLine("\n---Inserting some elements to the list---");
            list.InsertAt("string 5", 5);
            list.InsertAt("appear", list.Count - 1);
            list.InsertAt("string11", list.Count);
            Console.WriteLine("The new list is: " + list.ToString());
            Console.WriteLine("The new list count is: " + list.Count);

            Console.WriteLine("\n---Finding specific elements from the list---");
            Console.WriteLine("The index of 'element 9' is: " + list.Find("element 9"));
            Console.WriteLine("The index of 'element 111' is: " + list.Find("element 111"));

            Console.WriteLine("\n---Finding the maximal and the minimal element in the list---");
            Console.WriteLine("The minimal element in the list is: " + list.Min());
            Console.WriteLine("The maximal element in the list is: " + list.Max());

            Console.WriteLine("\n---Clearing the list---");
            list.Clear();
            Console.WriteLine("List count after clearing the list: " + list.Count);
            Console.WriteLine("List capacity after clearing the list: " + list.Capacity);

            // We cannot use Min() and Max() on "test" because it doesn't implement IComparable<>
            GenericList<Point2D> test = new GenericList<Point2D>();
            test.Add(new Point2D(5, 6));
            test.Add(new Point2D(-2, 1));
            test.Add(new Point2D(-12, -11));
            //test.Min();
            //test.Max()
        }
Ejemplo n.º 4
0
        static void Main()
        {
            GenericList<string> myList = new GenericList<string>();
            Console.WriteLine(myList.Capacity);
            Console.WriteLine(myList.Count);
            Console.WriteLine(myList.Elements);
            myList.Add("1");
            myList.Add("2");

            myList.Add("3");
            myList.Add("4");
            myList.Add("Gosho");
            myList.RemoveAt(3);
            Console.WriteLine(myList.Capacity);
            Console.WriteLine(myList.Count);
            Console.WriteLine(myList.Elements);
            myList.InsertAt(0, "Viki");
            Console.WriteLine(myList.FindIndex("Viki"));
            Console.WriteLine(myList.FindIndex("1"));
            myList.InsertAt(0, "Viki");
            myList.InsertAt(5, "Viktor");
            myList.InsertAt(7, "Viktor");
            myList.Clear();
            myList.Add("Pesho");
        }
Ejemplo n.º 5
0
    static void Main()
    {
        GenericList <int> list = new GenericList <int>(2);

        list.Add(1);
        list.Add(13);
        list.Add(12);

        Console.WriteLine("Generic list contains: {0}", list);

        Console.WriteLine("Second element of the list is {0}", list[2]);

        Console.WriteLine("Smallest element in the list is {0}", list.Min <int>());

        Console.WriteLine("Biggest element in the list is {0}", list.Max <int>());

        Console.Write("Please enter a value to search: ");

        int valueToSearch = int.Parse(Console.ReadLine());

        Console.WriteLine("Position: {0}", list.Find(valueToSearch));

        list.Clear();

        Console.WriteLine("List Cleared -> {0}", list);
    }
Ejemplo n.º 6
0
 public static void Main()
 {
     GenericList<int> a = new GenericList<int>();
     a.Add(15);
     a.Add(20);
     a.Add(30);
     a.Add(40);
     a.Add(55);
     a.Add(60);
     a.Add(70);
     a.Add(100);
     a.Add(100);
     Console.WriteLine(a.Capacity);
     a.Add(15);
     a[2] = 500;
     Console.WriteLine(a);
     Console.WriteLine(a.IndexOf(30));
     Console.WriteLine(a.Contains(500));
     a.InsertAt(10, 59);
     a.InsertAt(11, 59);
     a.InsertAt(12, 59);
     a.InsertAt(13, 59);
     a.InsertAt(14, 59);
     a.InsertAt(15, 59);
     a.InsertAt(16, 59);
     Console.WriteLine(a);
     Console.WriteLine(a.Capacity);
     Console.WriteLine(a.IsEmpty);
     Console.WriteLine(a.Min());
     Console.WriteLine(a.Max());
     a.Clear();
 }
Ejemplo n.º 7
0
        public static void Main()
        {
            GenericList<int> list = new GenericList<int>();
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            Console.WriteLine("Making a new list:\n " + list);

            Console.WriteLine("Inserting a number 6 at position 2!");
            list.Insert(2, 6);
            Console.WriteLine(list);

            Console.WriteLine("The position of number 3 is {0}!", list.IndexOf(3));

            Console.WriteLine("Remove an element on position 3.");
            list.RemoveAt(3);
            Console.WriteLine(list);

            Console.WriteLine("The MIN element in the list is {0}", list.Min());
            Console.WriteLine("The MAX element in the list is {0}", list.Max());

            list.Clear();

            Console.WriteLine("The list after list.Clear()! \n" + list);

            //Console.WriteLine(list.Min());
        }
        public static void Main(string[] args)
        {
            var l = new GenericList<int>();

            l.Add(3);
            l.Add(4);
            l.Add(235252532);

            Console.WriteLine(l);

            l.Insert(1, 2);
            Console.WriteLine(l);

            Console.WriteLine(l.Find(4));

            l.RemoveAt(1);
            Console.WriteLine(l);

            l.Add(1);
            l.Add(7);
            l.Add(1);
            l.Add(9);
            l.Add(3);
            l.Add(2);
            l.Add(6);
            l.Add(8);
            Console.WriteLine(l);

            Console.WriteLine(l.Min());
            Console.WriteLine(l.Max());
            l.Clear();
            Console.WriteLine(l);
        }
Ejemplo n.º 9
0
 static void Main()
 {
     GenericList<int> test = new GenericList<int>(10);
     for (int i = 0; i < test.Length; i++)
     {
         test.Add(i);
     }
     Console.WriteLine(test.ToString());
     test.Remove(9);
     Console.WriteLine(test.ToString());
     test.Insert(9, 9);
     Console.WriteLine(test);
     GenericList<int> newTest = new GenericList<int>(10);
     for (int i = 0; i < newTest.Length - 1; i++)
     {
         newTest.Add(i);
     }
     Console.WriteLine(newTest);
     newTest.Insert(10, 9);
     Console.WriteLine(newTest);
     newTest.Clear();
     Console.WriteLine(newTest);
     Console.WriteLine(test[3]);
     GenericList<string> stringTest = new GenericList<string>(10);
     for (int i = 0; i < stringTest.Length - 2; i++)
     {
         stringTest.Add(i.ToString());
     }
     Console.WriteLine(stringTest);
     stringTest.Add("huehuehueheuhe");
     Console.WriteLine(stringTest);
     stringTest.Insert("Teehee", 9);
     Console.WriteLine(stringTest);
 }
Ejemplo n.º 10
0
        static void Main()
        {
            GenericList<int> nums = new GenericList<int>();
            nums.Add(5);
            nums.Add(10);
            nums.Add(50);

            Console.WriteLine(nums.Contains(10)); // output: True
            Console.WriteLine(nums[2]);           // output: 50

            nums[2] = 42;
            Console.WriteLine(nums[2]);           // output: 42

            Console.WriteLine(nums.IndexOf(42));  // output: 2

            Console.WriteLine(nums.Count);        // output: 3

            Console.WriteLine(nums);              // output: [item1, item2...]

            nums.RemoveAt(0);
            Console.WriteLine(nums.Count);        // output: 2

            nums.Clear();
            Console.WriteLine(nums.Count);        // output: 0
        }
Ejemplo n.º 11
0
        static void Main()
        {
            GenericList<int> list = new GenericList<int>(5);
            StringBuilder result = new StringBuilder();
            list.Add(3);
            list.InsertAt(0, 2);
            list.InsertAt(0, 1);
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            result.AppendLine("--REMOVE AT INDEX 1--");
            list.RemoveAt(1);
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            result.AppendLine("     MIN: " + list.Min());
            result.AppendLine("     MAX: " + list.Max());

            result.AppendLine("-----INDEX OF 3-----");
            result.AppendLine(list.IndexOf(3).ToString());
            result.AppendLine("-----INDEX OF 2-----");
            result.AppendLine(list.IndexOf(2).ToString());

            result.AppendLine("-----CLEAR LIST-----");
            list.Clear();
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            Console.WriteLine(result);
        }
        public static void Main()
        {
            Console.Title = "Problem 3.	Generic ";

            GenericList<int> numbers = new GenericList<int>();
            numbers.Add(5);
            numbers.Add(50);
            numbers.Add(500);
            numbers.Add(1000);

            Console.WriteLine(numbers.Max());
            Console.WriteLine(numbers.Min());

            Console.WriteLine(numbers.GetAtIndex(1));
            numbers.Insert(1, 25);
            Console.WriteLine(numbers.IndexOf(50));
            Console.WriteLine(numbers.Contains(5));
            numbers.Remove(5);
            Console.WriteLine(numbers);
            numbers.Clear();
            Console.WriteLine(numbers);

            Console.WriteLine();
            Console.WriteLine("Problem 4.	Generic List Version");
            System.Reflection.MemberInfo info = typeof(GenericList<>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }
        }
Ejemplo n.º 13
0
    public static void Main()
    {
        GenericList <int> list = new GenericList <int> (3);

        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.Add(4);
        list.Add(5);

        Console.WriteLine("Added new elements: ");
        Console.WriteLine(list.ToString());

        Console.WriteLine("Access by index 2: (not said to use indexers!): " + list.ItemAt(2));

        Console.WriteLine("After insert 10 at index 1: ");
        list.InsertAt(1, 10);
        Console.WriteLine(list.ToString());

        Console.WriteLine("After remove at index 5: ");
        list.RemoveAt(5);
        Console.WriteLine(list.ToString());

        Console.WriteLine("Min: " + list.Min());
        Console.WriteLine("Max: " + list.Max());

        Console.WriteLine("Index of 10: " + list.IndexOf(10));
        Console.WriteLine("Index of 100: " + list.IndexOf(100));

        list.Clear();
        Console.WriteLine("After clearing: Count = {0}, Capacity = {1}", list.Count, list.Capacity);
    }
        static void Main()
        {
            GenericList <Decimal> testGenList = new GenericList <decimal>();

            testGenList.Add(125.53M);
            testGenList.Add(123);
            testGenList.Add(100);
            testGenList.Add(1000);
            testGenList.Add(10000);
            Console.WriteLine(testGenList.ToString());
            Console.WriteLine(testGenList.Find(100));
            Console.WriteLine(testGenList.Access(1));
            Console.WriteLine(testGenList.Capacity);
            testGenList.Insert(0, 0);
            testGenList.Insert(5, 3);
            testGenList.Remove(testGenList.Count - 1);
            Console.WriteLine(testGenList.ToString());
            testGenList.Insert(16.16M, testGenList.Count - 1);
            testGenList.Insert(17.17M, testGenList.Count - 1);
            testGenList.Insert(18.18M, testGenList.Count - 1);
            testGenList.Insert(19.19M, testGenList.Count - 1);
            Console.WriteLine(testGenList.ToString());
            Console.WriteLine(testGenList.Max());
            testGenList.Remove(testGenList.Find(testGenList.Max()));
            Console.WriteLine(testGenList.ToString());
            Console.WriteLine(testGenList.Max());
            Console.WriteLine(testGenList.Min());
            testGenList.Remove(0);
            Console.WriteLine(testGenList.Min());
            testGenList.Clear();
            Console.WriteLine(testGenList.ToString());
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            IGenericList <string> list = new GenericList <string>();

            list.Add("jedan");
            Console.WriteLine(list);
            list.Add("dva");
            Console.WriteLine(list);
            list.Add("tri");
            Console.WriteLine(list);
            list.Add("četiri");
            Console.WriteLine(list);
            list.Add("pet");
            Console.WriteLine(list);

            Console.WriteLine(list.Contains("nula"));

            Console.WriteLine("Foreach test:");
            foreach (string s in list)
            {
                Console.WriteLine(s);
            }

            list.RemoveAt(0);
            Console.WriteLine(list);
            list.Remove("tri");
            Console.WriteLine(list);
            Console.WriteLine(list.Count);
            Console.WriteLine(list.Remove("ayylmao"));
            Console.WriteLine(list.RemoveAt(5));
            list.Clear();
            Console.WriteLine(list);
            Console.WriteLine(list.Count);
            Console.ReadKey();
        }
Ejemplo n.º 16
0
 static void Main()
 {
     var newList = new GenericList<int>();
     for (int i = 0; i < 5; i++)
     {
         newList.Add(i);
     }
     newList.Remove(3);
     newList.Insert(3, 3);
     Console.WriteLine("For each");
     foreach (var item in newList)
     {
         Console.WriteLine(item);
     }
     Console.WriteLine();
     Console.WriteLine("Index of");
     Console.WriteLine(newList.IndexOf(2));
     Console.WriteLine();
     Console.WriteLine("ToString");
     Console.WriteLine(newList);
     Console.WriteLine();
     Console.WriteLine("Min");
     Console.WriteLine(newList.Min());
     Console.WriteLine();
     Console.WriteLine("Max");
     Console.WriteLine(newList.Max());
     newList.Clear();
     Console.WriteLine("After clear");
     Console.WriteLine(newList);
     Console.WriteLine("Test whatever you want!");
 }
Ejemplo n.º 17
0
    static void Main(string[] args)
    {
        GenericList <int> someList = new GenericList <int>();

        someList.Add(1);
        someList.Add(2);
        someList.Add(111);

        Console.WriteLine("Full list : {0}", someList);

        Console.WriteLine("Find 2 : {0}", someList.Find(2, 1));
        Console.WriteLine("Find 333 : {0}", someList.Find(333));

        someList.RemoveAt(1);

        Console.WriteLine("Full list after remove position 1: {0}", someList);

        someList.AddAt(1, 4);

        Console.WriteLine("After add 4 at position 1 : {0}", someList);

        someList.Clear();

        Console.WriteLine("After clear : {0}", someList);
    }
Ejemplo n.º 18
0
 static void Main(string[] args)
 {
     var listtt = new List<int>();
     GenericList<int> myList = new GenericList<int>(10);
     //ADD
     myList.Add(1);
     myList.Add(2);
     myList.Add(3);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Insert element");
     //INSERT AT GIVEN POSITION
     myList.Insert(3, 50);
     myList.Insert(3, 60);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Find element:");
     //FIND CERTAINT ELEMENT AT WHAT INDEXES EXISTS
     myList.Find(25);
     Console.WriteLine("Remove element:");
     //REMOVE AT CERTAIN INDEX
     myList.Remove(2);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Find maximum");
     //FIND MAX
     Console.WriteLine(myList.Max());
     Console.WriteLine("Find minimum");
     //FIND MIN
     Console.WriteLine(myList.Max());
     //CLEAR ALL
     Console.WriteLine("Clear all");
     myList.Clear();
     Console.WriteLine(myList.ToString());
 }
Ejemplo n.º 19
0
        static void Main()
        {
            GenericList<int> numbers = new GenericList<int>()
            {
                0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
            };
            Console.WriteLine("Creating a GenericList with the numbers from 1 to 20 \n {0} \n", numbers);

            numbers.Remove(19);
            Console.WriteLine("Removing the 19th element \n {0} \n", numbers);

            numbers.Add(100);
            Console.WriteLine("Adding an element to the end of the GenericList \n {0} \n", numbers);

            numbers.Insert(30, 10);
            Console.WriteLine("Inserting an element on the 10th position \n {0} \n", numbers);

            numbers[3] = 9;
            Console.WriteLine("Changing the value of the 3rd index number \n {0} \n", numbers);

            Console.WriteLine("Trying to find number 4 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(4), numbers.Find(4));
            Console.WriteLine("Trying to find number 80 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(80), numbers.Find(80));
            Console.WriteLine("Min element: {0}, Max element: {1} \n", numbers.Min(), numbers.Max());

            numbers.Clear();
            Console.WriteLine("Cleared GenericList: \n {0} \n", numbers);

            Type type = typeof(GenericList<>);
            VersionAttribute attribute = (VersionAttribute)type.GetCustomAttributes(false).LastOrDefault();
            Console.WriteLine("Version: " + attribute.Version);
        }
        static void Main()
        {
            GenericList<string> glist = new GenericList<string>();
            glist.Add("First");
            glist.Add("Second");
            glist.Add("Third");
            glist.Add("Pesho");
            glist.Add("Gosho");
            glist.Add("Tosho");

            glist.Insert(0, "Purvi Pesho");

            Console.WriteLine(glist);
            Console.WriteLine("Index of \"Second\": {0}", glist.IndexOf("Second"));
            Console.WriteLine("Does contain \"Toshkata\": {0}", glist.Contains("Toshkata"));
            Console.WriteLine("Does contain \"Pesho\": {0}", glist.Contains("Pesho"));

            Console.WriteLine();

            glist.Remove(2);
            glist.Remove(2);

            Console.WriteLine(glist);
            Console.WriteLine("Min Value: {0}", glist.Min());
            Console.WriteLine("Max Value: {0}", glist.Max());

            glist.Clear();

            Console.WriteLine(glist);
        }
Ejemplo n.º 21
0
 static void Main()
 {
     GenericList<Decimal> testGenList = new GenericList<decimal>();
     testGenList.Add(125.53M);
     testGenList.Add(123);
     testGenList.Add(100);
     testGenList.Add(1000);
     testGenList.Add(10000);
     Console.WriteLine(testGenList.ToString());
     Console.WriteLine(testGenList.Find(100));
     Console.WriteLine(testGenList.Access(1));
     Console.WriteLine(testGenList.Capacity);
     testGenList.Insert(0, 0);
     testGenList.Insert(5, 3);
     testGenList.Remove(testGenList.Count - 1);
     Console.WriteLine(testGenList.ToString());
     testGenList.Insert(16.16M, testGenList.Count - 1);
     testGenList.Insert(17.17M, testGenList.Count - 1);
     testGenList.Insert(18.18M, testGenList.Count - 1);
     testGenList.Insert(19.19M, testGenList.Count - 1);
     Console.WriteLine(testGenList.ToString());
     Console.WriteLine(testGenList.Max());
     testGenList.Remove(testGenList.Find(testGenList.Max()));
     Console.WriteLine(testGenList.ToString());
     Console.WriteLine(testGenList.Max());
     Console.WriteLine(testGenList.Min());
     testGenList.Remove(0);
     Console.WriteLine(testGenList.Min());
     testGenList.Clear();
     Console.WriteLine(testGenList.ToString());
 }
Ejemplo n.º 22
0
    static void Main()
    {
        var test = new GenericList <int>(2);

        for (int i = 0; i < 25; i++)
        {
            test.Add(i * 4);
        }

        Console.WriteLine(test);

        test.Remove(5);

        Console.WriteLine(test);

        test.Insert(9, 77);
        Console.WriteLine(test);

        Console.WriteLine("ByValue: {0} ", test.FindIndexByValue(77));
        Console.WriteLine("ByIndex: {0}", test[17]);
        Console.WriteLine("Max: {0} ", test.GetMax());
        Console.WriteLine("Min: {0}", test.GetMin());

        test.Clear();
    }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            GenericList<string> genericList = new GenericList<string>();
            genericList.Add("a");
            genericList.Add("b");
            genericList.Add("c");
            Console.WriteLine(genericList);
            Console.WriteLine("Max = {0}, Min = {1}",genericList.Max(),genericList.Min());
            Console.WriteLine("Remove b");
            genericList.Remove("b");
            Console.WriteLine(genericList);
            Console.WriteLine("genericList[0] = "+genericList.Access(0));
            Console.WriteLine("index of c = "+genericList.FindIndex("c"));
            genericList.Clear();
            genericList.Add("rom");
            genericList.Add("mon");
            genericList.Add("dom");
            Console.WriteLine(genericList);
            Console.WriteLine("Insert zom (index = 1)");
            genericList.Insert("zom",1);
            Console.WriteLine(genericList);
            Console.WriteLine(genericList.Contains("mon"));
            Console.WriteLine(genericList.Contains("aaa"));

            Type type = typeof(GenericList<>);
            object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
            foreach (VersionAttribute attr in allAttributes)
            {
                Console.WriteLine("This class's version is {0}.", attr.Version);
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("GenericList Task\r\n");

            GenericList<string> list = new GenericList<string>("first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eight");
            Console.WriteLine(list);

            list[3] = "fourth changed";
            list.Add("nineth");
            list.Insert(0, "zero");
            list.Remove(5);
            Console.WriteLine("Modified list(indexed access, add, insert, remove):\r\n" + list);

            int found = list.Find("second");
            Console.WriteLine("Search for 'second': index={0}, element={1}", found, list[found]);
            found = list.Find("bla");
            Console.WriteLine("Search for 'bla': index={0}", found);

            Console.WriteLine("Min element: " + list.Min());
            Console.WriteLine("Max element: " + list.Max());

            list.Clear();
            Console.WriteLine("Clearing list: " + list);

            Console.WriteLine("\r\nPress Enter to finish");
            Console.ReadLine();
        }
Ejemplo n.º 25
0
        static void GenericListTest()
        {
            var listForTest = new GenericList <int>();

            listForTest.Add(0);
            listForTest.Add(1);
            listForTest.Add(2);
            listForTest.Add(3);
            listForTest.Add(4);
            listForTest.Add(5);
            listForTest.Add(6);
            listForTest.Add(7);
            // Base capacity of my list is 8. Notice the auto-grow when it exceeds.
            listForTest.Add(8);
            listForTest.Add(9);

            Console.WriteLine(listForTest);
            Console.WriteLine("Item by index 3: " + listForTest.ElementAt(3));
            listForTest.RemoveAt(3);
            Console.WriteLine("Removing item by index 3: " + listForTest);
            listForTest.InsertAt(3, 100);
            Console.WriteLine("Adding item 100 at index 3: " + listForTest);
            Console.WriteLine("Search for the element with value 100. (Returns the index): " + listForTest.Find(100));
            Console.WriteLine("List max: " + listForTest.Max());
            Console.WriteLine("List min: " + listForTest.Min());
            listForTest.Clear();
            Console.WriteLine("List cleared: " + listForTest);
        }
    static void Main()
    {
        var intList = new GenericList<int>();

        intList.Add(1);
        intList.Add(2);
        intList.Add(3);
        intList.Add(4);
        intList.Add(5);
        Console.WriteLine("Number of elements: {0}", intList.Count);
        Console.WriteLine(intList);
        intList[4] = 133;
        Console.WriteLine(intList);

        intList.Remove(2);
        Console.WriteLine(intList);

        intList.Insert(0, 4);
        Console.WriteLine(intList);

        Console.WriteLine(intList.Find(133));

        Console.WriteLine(intList.Contains(4));

        Console.WriteLine("Max = " + intList.Max());
        Console.WriteLine("Min = " + intList.Min());

        intList.Clear();
        Console.WriteLine("Elemets in List: " + intList.Count);

        Type type = typeof(GenericList<>);
        object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
        Console.WriteLine("GenericsList's version is {0}", ((VersionAttribute)allAttributes[0]).Version);
    }
Ejemplo n.º 27
0
        public static void Main()
        {
            var list = new GenericList <int>(20);

            list.Add(15);
            list.Add(22);
            list.Add(44);
            list.Add(-22);
            list.Add(-18);
            list.Add(int.MaxValue);

            // list after only adding elements in it -> 15, 22, 44, -22, -18, int.MaxValue
            Console.WriteLine(list);
            list.InsertAt(2, 1024);

            // list after inserting element at given index
            // 15, 22, 1024, 44, -22, -18, int.MaxValue
            Console.WriteLine(list);

            list.RemoveAt(0);
            // list after removing element at given index
            // 22, 1024, 44, -22, -18, int.MaxValue*/

            Console.WriteLine(list);

            Console.WriteLine("list[2] = {0}", list[2]);
            Console.WriteLine("Max item: list[{0}] = {1}", list.GetElementIndex(list.Max()), list.Max());
            Console.WriteLine("Min item: list[{0}] = {1}", list.GetElementIndex(list.Min()), list.Min());
            Console.WriteLine("Capacity: {0}, Count: {1}", list.Capacity, list.ElementsCount);
            list.Clear();
            Console.WriteLine("Count after clearing list: {0}", list.ElementsCount);
            // printed list after being cleared
            Console.WriteLine(list);
        }
Ejemplo n.º 28
0
        public static void Main()
        {
            Console.WriteLine("> Create new generic list...");
            GenericList<int> list = new GenericList<int>();
            PrintListData(list);

            Console.WriteLine("> Add four items...");
            list = new GenericList<int>(1, 2, 3, 4); // Use the constructor
            PrintListData(list);

            Console.WriteLine("> List is full, add one more item...");
            list.Add(5);
            PrintListData(list);

            Console.WriteLine("> Remove element at index 2...");
            list.RemoveAt(2);
            PrintListData(list);

            Console.WriteLine("> Insert element '3' at index 2...");
            list.InsertAt(3, 2);
            PrintListData(list);

            Console.WriteLine("> Find element '3'...");
            int item = 3;
            int index = list.Find(item);
            Console.WriteLine("Element '{0}' found at index {1}.\n", item, index);

            Console.WriteLine("> Find min and max value...");
            Console.WriteLine("Min: {0}", list.Min());
            Console.WriteLine("Max: {0}\n", list.Max());

            Console.WriteLine(">Clear the list...");
            list.Clear();
            PrintListData(list);
        }
Ejemplo n.º 29
0
        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>();
        }
Ejemplo n.º 30
0
        static void Main(string[] args)
        {
            GenericList<int> list = new GenericList<int>(3);
            list.Add(0);
            list.Add(1);
            list.Add(2);

            //Insert at position 2
            list.InsertAt(2,9);
            Console.WriteLine("The 2nd element is:{0}",list[2]);

            //Find the max value
            Console.WriteLine("Max value is:{0}", list.Max());

            //Remove index 2
            list.RemoveAt(2);
            Console.WriteLine(list[2]);
            Console.WriteLine("The 2nd element is:{0}", list[2]);
            //Find the min value
            Console.WriteLine("Min value is:{0}", list.Min());

            //Clear the list
            list.Clear();
            Console.WriteLine("The length of the list after it has been cleared:{0}", list.All.Length);
        }
Ejemplo n.º 31
0
    static void Main()
    {
        var intList = new GenericList <int>();

        intList.Add(1);
        intList.Add(2);
        intList.Add(3);
        intList.Add(4);
        intList.Add(5);
        Console.WriteLine("Number of elements: {0}", intList.Count);
        Console.WriteLine(intList);
        intList[4] = 133;
        Console.WriteLine(intList);

        intList.Remove(2);
        Console.WriteLine(intList);

        intList.Insert(0, 4);
        Console.WriteLine(intList);

        Console.WriteLine(intList.Find(133));

        Console.WriteLine(intList.Contains(4));

        Console.WriteLine("Max = " + intList.Max());
        Console.WriteLine("Min = " + intList.Min());

        intList.Clear();
        Console.WriteLine("Elemets in List: " + intList.Count);

        Type type = typeof(GenericList <>);

        object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
        Console.WriteLine("GenericsList's version is {0}", ((VersionAttribute)allAttributes[0]).Version);
    }
Ejemplo n.º 32
0
        static void Main()
        {
            GenericList<int> l = new GenericList<int>(1);

            l.Add(1);
            l.Add(2);
            l.Add(3);
            l.Add(4);
            l.Add(5);
            l.Add(-1);

            Console.WriteLine(l);

            l.RemoveAt(5);

            Console.WriteLine(l);

            l.InsertAt(0, -3);

            Console.WriteLine(l);

            Console.WriteLine(l.IndexOf(-3));

            Console.WriteLine(l.Max());
            Console.WriteLine(l.Min());

            l.Clear();

            Console.WriteLine(l);
        }
Ejemplo n.º 33
0
    static void Main()
    {
        var test = new GenericList<int>(2);

        for (int i = 0; i < 25; i++)
        {
            test.Add(i * 4);
        }

        Console.WriteLine(test);

        test.Remove(5);

        Console.WriteLine(test);

        test.Insert(9, 77);
        Console.WriteLine(test);

        Console.WriteLine("ByValue: {0} ", test.FindIndexByValue(77));
        Console.WriteLine("ByIndex: {0}", test[17]);
        Console.WriteLine("Max: {0} ", test.GetMax());
        Console.WriteLine("Min: {0}" , test.GetMin());

        test.Clear();
    }
Ejemplo n.º 34
0
        static void Main(string[] args)
        {
            GenericList<int> test = new GenericList<int>(1);
            test.Add(2);
            test.Add(45);
            test.Add(4);
            test.Add(50);
            test.Add(0);
            test.Add(-1000);

            Console.WriteLine(test);

            test.Remove(4);

            Console.WriteLine(test);

            test.Insert(0, 560);

            Console.WriteLine(test);

            Console.WriteLine(test.Find(123));

            Console.WriteLine(test.Max());
            Console.WriteLine(test.Min());

            test.Clear();

            Console.WriteLine(test);
        }
Ejemplo n.º 35
0
        static void Main()
        {
            GenericList<int> genList = new GenericList<int>();
            Console.WriteLine("Add elements, double capacity when exceeded capacity:");
            genList.AddElement(8);
            genList.AddElement(2);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            genList.AddElement(1);
            genList.AddElement(5);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            genList.AddElement(9);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            Console.WriteLine("Insert element:");
            Console.WriteLine(genList);
            genList.InsertElement(4, 789);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            Console.WriteLine("Remove element:");
            genList.RemoveElement(3);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);

            Console.WriteLine("Find min and max elements:");
            Console.WriteLine("\nThe min element in genList is: {0}", genList.Min());
            Console.WriteLine("\nThe max element in genList is: {0}", genList.Max());

            Console.WriteLine("Clear the list:");
            genList.Clear();
            Console.WriteLine("Count = {0}", genList.Count);
            Console.WriteLine("\nThe genList is now cleared.");
        }
        public static void Main(string[] args)
        {
            //test GenericList
            Console.WriteLine("Test \"GenericList\"");
            GenericList<int> list = new GenericList<int>(5);

            int length = list.Capacity;
            for (int i = 0; i < length; i++)
            {
                list.Add(i + 5);
            }

            Console.WriteLine("list -> element at index 1 = {0}", list.GetElement(1));
            Console.WriteLine();

            Console.WriteLine("list -> {0}", list);
            Console.WriteLine();

            list.InsertElementAtIndex(3, 7);
            list.InsertElementAtIndex(3, 7);
            list.InsertElementAtIndex(3, 7);
            list.InsertElementAtIndex(3, 7);
            list.InsertElementAtIndex(3, 7);
            list.InsertElementAtIndex(3, 7);
            list.InsertElementAtIndex(3, 7);

            Console.WriteLine("list -> {0}", list);
            Console.WriteLine();

            list.Add(7);

            Console.WriteLine("list -> {0}", list);
            Console.WriteLine();

            list.RemoveElementAtIndex(3);
            list.RemoveElementAtIndex(3);
            list.RemoveElementAtIndex(3);
            list.RemoveElementAtIndex(3);
            list.RemoveElementAtIndex(3);
            list.RemoveElementAtIndex(3);
            list.RemoveElementAtIndex(list.Count - 1);

            Console.WriteLine("list -> {0}", list);
            Console.WriteLine();

            Console.WriteLine("find index of value 4 -> {0}", list.FindByValue(4));
            Console.WriteLine("list -> {0}", list);
            Console.WriteLine();

            Console.WriteLine("list min-element -> {0}", list.Min());
            Console.WriteLine("list max-element -> {0}", list.Max());
            Console.WriteLine();

            Console.WriteLine("Clear list:");
            list.Clear();

            Console.WriteLine("list -> {0}", list);
            Console.WriteLine();
        }
Ejemplo n.º 37
0
        static void Main()
        {
            var doubleList = new GenericList<double>();

            doubleList.Add(5.5);
            doubleList.Add(6.9);
            doubleList.Add(6.4);
            doubleList.Add(6.7);
            doubleList.Add(5.6);

            int count = doubleList.Count;
            double max = doubleList.Max();
            double min = doubleList.Min();

            Console.WriteLine(doubleList);
            Console.WriteLine("Max: {0}; Min: {1}; Count: {2}", max, min, count);

            doubleList.Remove(6.4);
            doubleList.Remove(5.5);
            doubleList.RemoveAt(1);

            count = doubleList.Count;
            max = doubleList.Max();
            min = doubleList.Min();

            Console.WriteLine(doubleList);
            Console.WriteLine("Max: {0}; Min: {1} Count: {2}", max, min, count);
            doubleList.Version();

            doubleList.Clear();
            bool isEmpty = doubleList.isEmpty;
            Console.WriteLine(isEmpty);
            Console.WriteLine(doubleList);

            var stringList = new GenericList<string>();

            stringList.Add("Kircho");
            stringList.Add("Jecho");
            stringList.Add("Mecho");
            stringList.Add("Vulcho");

            bool jecho = stringList.Contais("Jecho");
            bool nencho = stringList.Contais("Nencho");

            string who = stringList.ElementOf(0);
            int index = stringList.IndexOf("Vulcho");
            string maxString = stringList.Max();

            Console.WriteLine(stringList);
            Console.WriteLine("jecho: {0} \nnencho: {1} \nElement of 0 index: {2} \nIndex of Vulcho: {3} \nMax: {4}"
                , jecho, nencho, who, index, maxString);

            string indexer = stringList[3];
            Console.WriteLine(indexer);

            stringList.Insert("Gocho",2);
            Console.WriteLine(stringList[2]);
            stringList.Version();
        }
Ejemplo n.º 38
0
        static void Main(string[] args)
        {
            /*Testing is it working!*/

            GenericList<int> testingGenerics = new GenericList<int>(1);

            // Getting elements:
            testingGenerics.AddElement(1);
            testingGenerics.AddElement(2);
            testingGenerics.AddElement(3);
            testingGenerics.AddElement(4);
            testingGenerics.AddElement(5);
            testingGenerics.AddElement(6);
            Console.WriteLine("The Array is: ");
            Console.WriteLine(testingGenerics);

            // Testing indexator:
            Console.Write("The int on index [3] is: ");
            Console.WriteLine(testingGenerics[3]);
            Console.Write("Changing it to 99: ");
            testingGenerics[3] = 99;
            Console.WriteLine(testingGenerics[3]);

            // Testing remove by index:
            Console.WriteLine();
            Console.WriteLine("Removing element [1]:");
            testingGenerics.RemoveElement(1);
            Console.Write("The new array is: ");
            Console.WriteLine(testingGenerics);

            // Testing the inserting by index:
            Console.WriteLine("Inserting a new element with index[0] = 100");
            testingGenerics.InsertElement(0, 100);
            Console.Write("The new array is: ");
            Console.WriteLine(testingGenerics);

            // Testing element counter:
            Console.WriteLine("The count of elements is: " + testingGenerics.Count);

            // Finding element:
            Console.Write("The element 3 is on index : ");
            Console.WriteLine(testingGenerics.FindElement(3));
            Console.WriteLine();

            //Testing to string
            Console.Write("To String: ");
            Console.WriteLine(testingGenerics.ToString());

            //Testing min & max element
            Console.WriteLine("Min element is: " + testingGenerics.MinElement());
            Console.WriteLine("Max element is: " + testingGenerics.MaxElement());
            Console.WriteLine();

            //clearing the list
            testingGenerics.Clear();
            Console.WriteLine("Cleared array: " + testingGenerics);
        }
Ejemplo n.º 39
0
        static void Main()
        {
            var testArray = new GenericList<int>(10); //we are obliged to pass the initial capacity of the list

            for (int i = 0; i < 10; i++) //adds 10 elements to the array
            {
                testArray.Add(i);
            }

            testArray.Insert(0, 15); //inserts an element with value 15 at index 0 of the list, the list doubles its capacity

            foreach (var item in testArray) //due to the implementation of IEnumerable we are able to print the GenericList with a foreach loop
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            testArray.Clear(); //we clear the GenericList and now it holds nothing, Count is reset to 0, Capacity stays the same

            foreach (var item in testArray) //nothing will print as there are no elements present
            {
                Console.WriteLine(item);
            }

            testArray.Add(7);
            testArray.Add(4);
            testArray.Add(5);

            foreach (var item in testArray)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            testArray.Insert(2, 61); //inserts 61 at index 2 (where 5 currently is)
            Console.WriteLine();

            foreach (var item in testArray)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            testArray.Remove(1); //removes the element at index 1 (4)
            Console.WriteLine();

            foreach (var item in testArray)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\nIndex of '7' = " + testArray.IndexOf(7)); //returns the index of 7
            Console.WriteLine("\nElement with max value = " + testArray.Max());
            Console.WriteLine("\nElement with min value = " + testArray.Min());

            Console.WriteLine("\nPrint the List: " + testArray.ToString()+"\n");
        }
Ejemplo n.º 40
0
        private static void Main(string[] args)
        {
            var numbers = new GenericList<int>();

            // populate the list with  numbers from 0 to 19
            Console.WriteLine("Adding numbers to the list...");
            for (var i = 0; i < 20; i++)
            {
                numbers.Add(i);
            }
            Console.WriteLine(numbers);

            // remove element at position 10
            Console.WriteLine("Removing number at position 10...");
            numbers.RemoveAt(10);
            Console.WriteLine(numbers);

            // insert a number at position 10
            Console.WriteLine("Inserting number 333 at position 10");
            numbers.Insert(10, 333);
            Console.WriteLine(numbers);

            // check if the list contains 333
            Console.WriteLine("The list contains 333: {0} ", numbers.Contains(333) ? "True" : "False");

            //accessing element by index
            Console.WriteLine("Accessing index 14");
            Console.WriteLine(numbers[14]);

            //getting the index of number 5
            Console.WriteLine("Getting the index of number 5");
            Console.WriteLine(numbers.IndexOf(5));

            //change the number at index 10 
            Console.WriteLine("Changing the number at index 10 to 555");
            numbers[10] = 555;
            Console.WriteLine(numbers);

            //clearing the numbers
            Console.WriteLine("Clearing the numbers...");
            numbers.Clear();
            Console.WriteLine(numbers);

            //Problem 4. Version
            Console.WriteLine("Version information for {0}", numbers.GetType());
            var type = typeof (GenericList<>);
            VersionAttribute versionAttr;
            foreach (Attribute attr in type.GetCustomAttributes(true))
            {
                versionAttr = attr as VersionAttribute;
                if (versionAttr != null)
                {
                    Console.WriteLine("Version of {0} : {1}", type, versionAttr.Version);
                }
            }
        }
Ejemplo n.º 41
0
        public void ClearShouldClearList()
        {
            for (int i = 0; i <= 5; i++)
            {
                ints.Add(i);
            }

            ints.Clear();
            Assert.AreEqual(ints.Count, 0);
        }
Ejemplo n.º 42
0
        public void ClearListBehaviorTest()
        {
            var amount = 10;

            for (int i = 0; i < amount; ++i)
            {
                _list.Add(i);
            }
            _list.Clear();

            Assert.AreEqual(0, _list.Count);
        }
Ejemplo n.º 43
0
        static void Main()
        {
            GenericList <int> testList = new GenericList <int>(1);

            // Test Autogrow
            for (int i = 1; i < 6; i++)
            {
                testList.Add(i);
            }

            // ToString test
            Console.WriteLine("ToString test");
            Console.WriteLine(testList);
            Console.WriteLine();

            // Test indexer
            Console.WriteLine("Indexer test, get element at index 2: {0}", testList[2]);
            Console.WriteLine();

            // Remove element at index
            testList.RemoveAt(2);

            Console.WriteLine("After removal at index 2");
            Console.WriteLine(testList);
            Console.WriteLine();

            // Element insert test
            Console.WriteLine("Insert at index 2");
            testList.InsertAt(2, 3);
            Console.WriteLine("Insert at last index");
            testList.InsertAt(testList.Count, testList[testList.Count - 1] + 1);
            Console.WriteLine(testList);
            Console.WriteLine();

            // Search test
            Console.WriteLine("Find element 5");
            Console.WriteLine("Index of element 5: {0}", testList.Find(5));
            Console.WriteLine();

            // Max() and Min() test
            Console.WriteLine("Max element: {0}", testList.Max());
            Console.WriteLine("Min element: {0}", testList.Min());
            Console.WriteLine();

            // Clear list
            Console.WriteLine("Clear list and print");
            testList.Clear();
            Console.WriteLine(testList);
        }
Ejemplo n.º 44
0
        public static void Test()
        {
            GenericList <int> k = new GenericList <int>(4);

            k.Add(3);
            k.Add(4);
            k.Add(5);
            k.InsertAt(1, 324);
            k.Add(10);
            k.Add(11);
            Console.WriteLine(k.ToString());
            Console.WriteLine("Max ={0} Min= {1} \n Element at index 3 is:{2} \n Index of element 324 is:{3}", k.Max(), k.Min(), k[3], k.IndexOf(324));
            k.Clear();
            Console.WriteLine(k.ToString());
        }
    static void Main()
    {
        GenericList <int> dynamicList = new GenericList <int>(2);

        dynamicList.Add(1);
        dynamicList.Add(2);
        dynamicList.Add(3);
        dynamicList.Add(4);
        dynamicList.Add(5);
        dynamicList.Add(6);
        dynamicList.Add(7);
        dynamicList.Add(8);


        Console.WriteLine("Count: " + dynamicList.Count);
        Console.WriteLine(dynamicList);
        Console.WriteLine();
        var element = dynamicList.Access(4);

        Console.WriteLine("Element with index 4 is {0}", element);

        // Remove element
        Console.WriteLine();
        dynamicList.Remove(2);
        Console.WriteLine(dynamicList);

        // Insert element
        Console.WriteLine();
        dynamicList.Insert(3, 2);
        Console.WriteLine(dynamicList);

        // Min and Max number in list
        Console.WriteLine();
        Console.WriteLine("Min : " + dynamicList.Min());
        Console.WriteLine("Max : " + dynamicList.Max());

        // Clear list
        Console.WriteLine();
        dynamicList.Clear();

        Console.WriteLine(dynamicList);
        Console.WriteLine(dynamicList.Count);
        Console.WriteLine();

        var attributes = typeof(GenericList <>).GetCustomAttributes(typeof(Version), false);

        Console.WriteLine("Version: " + attributes[0]);
    }
Ejemplo n.º 46
0
        static void Main()
        {
            GenericList <int> test = new GenericList <int>();

            test.Add(1);
            test.Add(2);
            test.Add(54);
            test.Add(5);
            test.Add(6);
            Console.WriteLine("check ToString()");
            Console.WriteLine(test);
            Console.WriteLine("check capacity");
            Console.WriteLine(test.Capacity);
            Console.WriteLine("check count");
            Console.WriteLine(test.Count);
            Console.WriteLine("check foreach");
            foreach (var item in test)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("check indexer");
            for (int i = 0; i < test.Count; i++)
            {
                Console.WriteLine(test[i]);
            }
            Console.WriteLine("check accessing element at index 3");
            Console.WriteLine(test[3]);
            Console.WriteLine("check remove element at index 0");
            test.Remove(0);
            Console.WriteLine(test);
            Console.WriteLine("check insert element 256 at index 2");
            test.Insert(256, 2);
            Console.WriteLine(test);
            Console.WriteLine("check index of element 6");
            int index = test.IndexOf(6);

            Console.WriteLine(index);
            Console.WriteLine("check index of element 102");
            index = test.IndexOf(102);
            Console.WriteLine(index);
            Console.WriteLine("check min element");
            Console.WriteLine(test.Min());
            Console.WriteLine("check max element");
            Console.WriteLine(test.Max());
            Console.WriteLine("check clear list");
            test.Clear();
            Console.WriteLine(test);
        }
Ejemplo n.º 47
0
        static void Main()
        {
            GenericList <int> elements = new GenericList <int>();

            // Lege lijst
            Console.WriteLine(elements);
            Console.WriteLine("Aantal: {0}", elements.Count);
            Console.WriteLine("Capaciteit: {0}", elements.Capacity);

            // Auto-grow functionaliteit
            elements = new GenericList <int>(3);
            elements.Add(1);
            elements.Add(2);
            elements.Add(3);
            elements.Add(4);

            Console.WriteLine("\n" + elements);
            Console.WriteLine("Aantal: {0}", elements.Count);
            Console.WriteLine("Capaciteit: {0}", elements.Capacity);

            // Insert, RemoveAt
            elements.Clear();

            elements.Insert(0, 4);
            elements.Insert(0, 3);
            elements.Insert(0, 2);
            elements.Insert(0, 1);

            elements.RemoveAt(0);
            elements.RemoveAt(elements.Count - 1);

            Console.WriteLine("\n" + elements);
            Console.WriteLine("Aantal: {0}", elements.Count);
            Console.WriteLine("Capaciteit: {0}", elements.Capacity);

            // Contains, IndexOf
            Console.WriteLine("\nBevat element 2: {0}", elements.Contains(2));
            Console.WriteLine("Index van element 3: {0}", elements.IndexOf(3));

            // Max, Min
            Console.WriteLine("\nMin: {0}", elements.Min());
            Console.WriteLine("Max: {0}", elements.Max());

            Console.ReadKey();
        }
Ejemplo n.º 48
0
    static void Main(string[] args)
    {
        try
        {
            //Creating new list
            GenericList <int> intList = new GenericList <int>(20);

            //Overfill his capacity to make him auto grow
            int maxCapacity = intList.Capacity;
            for (int i = 1; i < maxCapacity * 2; i++)
            {
                intList.Add(i);
            }

            //Access elemtn by index
            Console.WriteLine(intList[9]);

            //Remove from index
            intList.RemoveAtIndex(9);

            //Insert new element at this position
            intList.InsertAtPosition(9, 100);

            //Look by value if the element is at this position
            Console.WriteLine(intList.FindByValue(100));

            //Find Min and Max value
            Console.WriteLine(intList.Min());
            Console.WriteLine(intList.Max());

            //Use overriden method ToString()
            Console.WriteLine(intList.ToString());

            //Clear list
            intList.Clear();

            //And print again whith ToString()
            Console.WriteLine(intList.ToString());
        }
        catch (Exception e)
        {
            Console.WriteLine("Error!" + e.Message);
        }
    }
Ejemplo n.º 49
0
 public void Clear()
 {
     if (ProxyClear != null)
     {
         ProxyClear();
     }
     else if (GenericList != null)
     {
         GenericList.Clear();
     }
     else if (NonGenericList != null)
     {
         NonGenericList.Clear();
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Ejemplo n.º 50
0
    static void Main()
    {
        var elements = new GenericList <int>();

        // empty GenericList
        Console.WriteLine(elements);
        Console.WriteLine("Count: {0}", elements.Count);
        Console.WriteLine("Capacity: {0}", elements.Capacity);

        // auto-grow functionality
        elements = new GenericList <int>(3);
        elements.Add(1);
        elements.Add(2);
        elements.Add(3);
        elements.Add(4);

        Console.WriteLine(Environment.NewLine + elements);
        Console.WriteLine("Count: {0}", elements.Count);
        Console.WriteLine("Capacity: {0}", elements.Capacity);

        // Insert, RemoveAt
        elements.Clear();

        elements.Insert(0, 4);
        elements.Insert(0, 3);
        elements.Insert(0, 2);
        elements.Insert(0, 1);

        elements.RemoveAt(0);
        elements.RemoveAt(elements.Count - 1);

        Console.WriteLine(Environment.NewLine + elements);
        Console.WriteLine("Count: {0}", elements.Count);
        Console.WriteLine("Capacity: {0}", elements.Capacity);

        // Contains, IndexOf
        Console.WriteLine(Environment.NewLine + "Contain element 2: {0}", elements.Contains(2));
        Console.WriteLine("Index of element 3: {0}", elements.IndexOf(3));

        // Max, Min
        Console.WriteLine(Environment.NewLine + "Min: {0}", elements.Min());
        Console.WriteLine("Max: {0}", elements.Max());
    }
    static void Main()
    {
        GenericList <int> list = new GenericList <int>();

        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.Add(4);
        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.Add(4);
        Console.WriteLine(list);

        list.InsertAt(7, 66);
        Console.WriteLine(list);

        list.Clear();
        Console.WriteLine(list);
        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.Add(4);
        Console.WriteLine(list);
        list.InsertAt(3, 66);
        Console.WriteLine(list);

        Console.WriteLine(list.FindIndex(3));
        Console.WriteLine(list.HasValue(66));

        list.RemoveAt(3);
        Console.WriteLine(list);
        Console.WriteLine(list.HasValue(66));

        Console.WriteLine(list.Min());
        Console.WriteLine(list.Max());

        Console.WriteLine();
        var allAttributes = typeof(GenericList <>).GetCustomAttributes(typeof(VersionAttribute), false);

        Console.WriteLine("Version: " + allAttributes[0]);
    }
Ejemplo n.º 52
0
        static void Main()
        {
            //create instance
            GenericList <int> genericList = new GenericList <int>();

            //add elements
            for (int i = 0; i < 16; i++)
            {
                genericList.Add(i);
            }

            Console.WriteLine(genericList);

            //remove elements
            for (int i = 0; i < 5; i++)
            {
                genericList.RemoveAt(i);
            }

            Console.WriteLine(genericList);

            //insert at position
            genericList.Insert(1, 32);
            genericList.Insert(16, 1);

            Console.WriteLine(genericList);

            //Find min and max
            Console.WriteLine(genericList.Min());
            Console.WriteLine(genericList.Max());

            Console.WriteLine(genericList.Count);
            Console.WriteLine(genericList.Capacity);

            //clear
            genericList.Clear();

            Console.WriteLine(genericList.Count);
            Console.WriteLine(genericList.Capacity);
        }
Ejemplo n.º 53
0
    static void Main()
    {
        GenericList <int> intList = new GenericList <int>();

        intList.Add(1);
        intList.Add(2);
        intList.Add(3);
        intList.Add(1);
        intList.Add(2);
        intList.Add(3);
        foreach (int num in intList)
        {
            Console.WriteLine(num);
        }
        Console.WriteLine("Number of elements: {0}", intList.Count);
        intList.Remove(3);
        foreach (int num in intList)
        {
            Console.WriteLine(num);
        }
        intList.RemoveAt(2);
        Console.WriteLine("Number of elements: {0}", intList.Count);
        foreach (int num in intList)
        {
            Console.WriteLine(num);
        }
        Console.WriteLine("Max element: {0}", intList.Max());
        Console.WriteLine("Min element: {0}", intList.Min());
        int element = 1;

        Console.WriteLine("Index of element {0} is {1}", element, intList.IndexOf(element));
        intList.InsertAt(28, 1);
        Console.WriteLine(string.Join(", ", intList));
        Console.WriteLine(intList.Contains(28));
        Console.WriteLine(intList.Contains(100));
        Console.WriteLine(intList);
        intList.Clear();
        Console.WriteLine(intList);
    }
Ejemplo n.º 54
0
    static void Main()
    {
        GenericList <int> listInt = new GenericList <int>(2);

        listInt.Add(2);
        listInt.Add(3);
        listInt.Add(4);
        listInt.Add(5);
        listInt.Add(6);
        listInt.Add(7);
        listInt.Insert(55, 3);

        Console.WriteLine(listInt.ToString());
        Console.WriteLine(listInt.FindElemIndexByValue(123));

        Console.WriteLine(listInt.Min());
        Console.WriteLine(listInt.Max());

        listInt.Clear();

        Console.WriteLine(listInt.ToString());
    }
Ejemplo n.º 55
0
        static void Main()
        {
            GenericList <int> listOfNumbers = new GenericList <int>(4);

            listOfNumbers.Add(5);
            listOfNumbers.Add(6);
            listOfNumbers.Add(7);
            listOfNumbers.Add(8);
            listOfNumbers.Remove(2);
            listOfNumbers.Insert(2, 7);
            listOfNumbers.Add(7);
            listOfNumbers.Add(1);
            listOfNumbers.Add(7);

            Console.WriteLine(listOfNumbers);
            Console.WriteLine(listOfNumbers.IsContain(7));
            Console.WriteLine("Min= " + listOfNumbers.Min());
            Console.WriteLine("Max= " + listOfNumbers.Max());

            listOfNumbers.Clear();
            Console.WriteLine(listOfNumbers);

            GenericList <string> listOfStrings = new GenericList <string>(8);

            listOfStrings.Add("a");
            listOfStrings.Add("b");
            listOfStrings.Add("c");
            listOfStrings.Add("Z");
            listOfStrings.Add("d");
            listOfStrings.Add("D");
            listOfStrings.Insert(1, "A");
            Console.WriteLine(listOfStrings);
            Console.WriteLine(listOfStrings.IsContain("A"));
            Console.WriteLine("Min= " + listOfStrings.Min());
            Console.WriteLine("Max= " + listOfStrings.Max());
        }
Ejemplo n.º 56
0
        static void Main(string[] args)
        {
            var list = new GenericList <int>();

            list.addElement(60);
            list.addElement(6);
            list.addElement(12);
            list.addElement(9756);
            list.addElement(3);
            list.addElement(74);
            list.addElement(687);
            list.addElement(123);
            list.Version();
            Console.WriteLine();
            Console.WriteLine("Start list --> {0}\n", list);
            Console.WriteLine("Max: ---> {0}\n", list.Max());
            Console.WriteLine("Min: ---> {0}\n", list.Min());

            list.Insert(7, 2);
            list.Insert(300, 1);
            Console.WriteLine("Insert: 300 and 7 ---> {0}\n", list);

            Console.WriteLine("Accessed by index 3 --> {0}\n", list.Access(3));

            Console.WriteLine(list.Contains(74));
            Console.WriteLine(list.Contains(4));
            Console.WriteLine();

            list.removeElement(4);
            list.removeElement(6);
            Console.WriteLine("After removal ---> {0}\n", list);

            Console.WriteLine("Found indexes:");
            Console.WriteLine("Index of 1 --> {0}", list.FindIndex(1));
            Console.WriteLine("Index of 60 --> {0}\n", list.FindIndex(60));
            Console.WriteLine("Final list --> {0}\n", list);
            // list = new GenericList<int>();
            list.Clear();
            Console.WriteLine("Cleared --> {0}\n", list);

            list.addElement(60);
            list.addElement(6);
            list.addElement(12);
            list.addElement(9756);
            list.addElement(3);
            list.addElement(74);
            list.addElement(687);
            list.addElement(123);
            list.addElement(60);
            list.addElement(6);
            list.addElement(12);
            list.addElement(9756);
            list.addElement(3);
            list.addElement(74);
            list.addElement(687);
            list.addElement(123);
            list.addElement(60);
            list.addElement(6);
            list.addElement(12);
            list.addElement(9756);
            list.addElement(3);
            list.addElement(74);
            list.addElement(687);
            list.addElement(123);
            Console.WriteLine("List with more than 16 symbols --> {0}", list);
        }
 public void GenericListClearList()
 {
     intList.Clear();
     Assert.IsTrue(intList.Size == 0);
 }
Ejemplo n.º 58
0
        /// <summary>
        ///     Tests the generic list methods.
        /// </summary>
        public void TestGenericListMethods()
        {
            var list = new GenericList <int> {
                2, 3, 4, 5, 6, 7, 8, 4, 10
            };

            Console.WriteLine("Initial list");
            Console.WriteLine(list);
            list.Version();
            Console.WriteLine();

            // adding an element
            Console.WriteLine("Adding an element");
            Console.WriteLine("Adding element with value 1 to the end of the list:");
            list.Add(1);
            Console.WriteLine(list);
            Console.WriteLine();

            // accessing element by index
            Console.WriteLine("Accessing element by index");
            Console.WriteLine("The element at index {0} is {1}", 2, list[2]);
            Console.WriteLine();

            // finding element index by given value
            Console.WriteLine("Finding element index by given value");
            Console.WriteLine("The first index of {0} is {1}", 4, list.IndexOf(4));
            Console.WriteLine("The last index of {0} is {1}", 4, list.LastIndexOf(4));
            Console.WriteLine();

            // removing element by index
            Console.WriteLine("Removing element by index");
            list.RemoveAt(1);
            Console.WriteLine("Removing the element at index 1, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            // removing element by value
            Console.WriteLine("Removing element by value");
            list.Remove(7);
            Console.WriteLine("Removing the element with value 7, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            // inserting element at given position
            Console.WriteLine("Inserting element at given position");
            list.InsertAt(2, 8);
            Console.WriteLine("Inserted element with value 8 at index 2, result:");
            Console.WriteLine(list);
            Console.WriteLine();

            // checking if the list contains a value
            Console.WriteLine("Checking if the list contains a value");
            Console.WriteLine("Checking if the list contains an element with value 2");
            Console.WriteLine(list.Contains(2));
            Console.WriteLine("Checking if the list contains an element with value 11");
            Console.WriteLine(list.Contains(11));
            Console.WriteLine();

            // finding the minimal and maximal element in the GenericList<T>
            Console.WriteLine("Finding the minimal and maximal element in the GenericList<T>");
            Console.WriteLine("The minimal element in the GenericList is {0}", list.Min());
            Console.WriteLine("The maximal element in the GenericList is {0}", list.Max());
            Console.WriteLine();

            // clearing the list
            Console.WriteLine("Clearing the list");
            Console.WriteLine("GenericList count before clearing: {0}", list.Count);
            list.Clear();
            Console.WriteLine("GenericList count after clearing: {0}", list.Count);
            Console.WriteLine("Displaying the elements in the GenericList: {0}", list);
            Console.WriteLine();

            // adding new elements to the GenericList
            Console.WriteLine("Adding new elements to the GenericList");
            list.Add(6);
            list.Add(4);
            Console.WriteLine("GenericList: {0}", list);
            Console.WriteLine();
        }
Ejemplo n.º 59
0
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var path = new Path();

            path.AddPoint(new Point3D(5, 36, 7.9));
            path.AddPoint(new Point3D(15, 6, 7));
            path.AddPoint(new Point3D(5.4, 26, 7));
            path.AddPoint(new Point3D(5.4, 16, 27));
            path.AddPoint(new Point3D(25.5, 6, 7));

            PathStorage.Save(path, "savedPoints");

            var otherPath = PathStorage.Load("savedPoints");

            Console.WriteLine("Test Structure");
            Console.WriteLine(otherPath);

            var a          = otherPath[0];
            var b          = otherPath[1];
            var distanseAB = Calculate.DistansBetweenTowPoints(a, b);

            Console.WriteLine($"Distance between first tow points in path is: {distanseAB:f4}");
            Console.WriteLine();

            var myList = new GenericList <int>(4);

            myList.Add(67);
            myList.Add(47);
            myList.Add(57);
            myList.Add(677);
            myList.Add(679);
            myList.Add(637);

            Console.WriteLine("Test Generic List");
            Console.WriteLine(myList);
            Console.WriteLine($"Number of elements: {myList.Count}");
            Console.WriteLine($"Index of 57 is: {myList.IndexOf(57)}");

            Console.WriteLine($"Element at index 3 is: {myList[3]}");
            myList.Remove(3);
            Console.WriteLine($"Element at index 3 is removed: { myList}");

            myList.Insirt(1, 100);
            Console.WriteLine($"100 is inserted at index 1: {myList}");

            Console.WriteLine($"Max value in myList is: {myList.Max()}");
            Console.WriteLine($"Min value in myList is: {myList.Min()}");

            myList.Clear();
            Console.WriteLine($"I am empty list.{myList}");
            Console.WriteLine();

            Console.WriteLine("Test Matrix");

            var firstMatrix = new Matrix <int>(2, 4);

            firstMatrix.FillMatrix();
            Console.WriteLine(firstMatrix);

            var secondMatrix = new Matrix <int>(2, 4);

            secondMatrix.FillMatrix();
            secondMatrix[1, 1] = 0;
            Console.WriteLine(secondMatrix);

            var thirdMatrix = new Matrix <int>(6, 2);

            thirdMatrix.FillMatrix();
            Console.WriteLine(thirdMatrix);

            Console.WriteLine($"Addition:\n{firstMatrix + secondMatrix}");
            Console.WriteLine($"Subtraction :\n{firstMatrix - secondMatrix}");
            Console.WriteLine($"Multiplication:\n{firstMatrix * thirdMatrix}");

            var isTrue = firstMatrix ? "True" : "False";

            Console.WriteLine(isTrue);

            isTrue = secondMatrix ? "True" : "False";
            Console.WriteLine(isTrue);
            Console.WriteLine();

            var classAttr = typeof(Startup).GetCustomAttributes <VersionAttribute>();

            foreach (var attribute in classAttr)
            {
                Console.WriteLine("{0}: {1}     Version: {2}", attribute.Component, attribute.Name, attribute.Version);
            }
        }
Ejemplo n.º 60
0
    static void Main()
    {
        //Create new list
        GenericList <int> list = new GenericList <int>(5);

        Console.WriteLine("Capacity: " + list.Capacity);
        Console.WriteLine("Count: " + list.Count);
        Console.WriteLine();

        //Add some values
        list.Add(0);
        list.Add(1);
        list.Add(2);
        list.Add(3);

        Console.WriteLine("--- add values 0, 1, 2, 3");
        Console.WriteLine("Capacity: " + list.Capacity);
        Console.WriteLine("Count: " + list.Count);
        Console.WriteLine("List: " + list);
        Console.WriteLine();

        //Add more values to cause increasing of capacity
        list.Add(4);
        list.Add(5);

        Console.WriteLine("--- add values 4, 5");
        Console.WriteLine("Capacity: " + list.Capacity);
        Console.WriteLine("Count: " + list.Count);
        Console.WriteLine("List: " + list);
        Console.WriteLine();

        //Remove a value
        list.RemoveAt(2);
        Console.WriteLine("--- remove value 2");
        Console.WriteLine("Capacity: " + list.Capacity);
        Console.WriteLine("Count: " + list.Count);
        Console.WriteLine("List: " + list);
        Console.WriteLine();

        //Insert it back
        list.Insert(2, 2);
        Console.WriteLine("--- insert value 2 at position 2");
        Console.WriteLine("Capacity: " + list.Capacity);
        Console.WriteLine("Count: " + list.Count);
        Console.WriteLine("List: " + list);
        Console.WriteLine();

        //Find it's index
        Console.WriteLine("Index of element with value 2: " + list.Find(2));
        Console.WriteLine();

        //Find the max element
        Console.WriteLine("Max: " + list.Max());
        Console.WriteLine();

        //Find the min element
        Console.WriteLine("Min: " + list.Min());
        Console.WriteLine();

        //Clear the list
        list.Clear();
        Console.WriteLine("--- clear the list");
        Console.WriteLine("Capacity: " + list.Capacity);
        Console.WriteLine("Count: " + list.Count);
        Console.WriteLine();
    }