Esempio n. 1
0
        public static void Main()
        {
            Type type = typeof(GenericList <>);

            object[] attr = type.GetCustomAttributes(false);

            foreach (var ver in attr)
            {
                if (ver.GetType() == typeof(VersionAttribute))
                {
                    Console.WriteLine("GeneriList v{0}\n",
                                      (ver as VersionAttribute).Build);
                }
            }

            GenericList <int> numList = new GenericList <int>();

            numList.Add(23, 77, -1);
            Console.WriteLine("Create a list and add to it 3 elements:\n{0}", numList);

            numList.Add(3, 4, 123, 0, -12, 31, -245, 125, 64, -122, 11, 77, 50, 4123, -517, 7, 12, 666);
            Console.WriteLine("Add to the list another 18 elements (resizes list):\n{0}", numList);

            numList.Remove(2);
            Console.WriteLine("Remove the element at index 2:\n{0}", numList);

            numList.Insert(2, 777);
            Console.WriteLine("Add element at index 2:\n{0}", numList);

            numList.Remove(numList.Count);
            Console.WriteLine("Remove the last element:\n{0}", numList);

            numList.Insert(numList.Count, 44);
            Console.WriteLine("Insert element at last position:\n{0}", numList);

            Console.WriteLine("Search for \"11\" in the list (-1 if not found): index {0}", numList.Find(11));

            Console.WriteLine("Max element in the list: {0}", numList.Max());
            Console.WriteLine("Min element in the list {0}", numList.Min());

            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            GenericList <int> numbers = new GenericList <int>();

            numbers.Add(3);
            numbers.Add(5);
            numbers.Add(15);
            numbers.Add(45);
            numbers.Add(67);

            Console.WriteLine("List: " + numbers);
            numbers.InsertElementAt(100, 3);
            Console.WriteLine("List after InsertElementAt: " + numbers);
            numbers.RemoveElementAtIndex(4);
            Console.WriteLine("List after RemoveElementAtIndex: " + numbers);
            Console.WriteLine("Element at index - 2: " + numbers.ElementAtIndex(2));
            Console.WriteLine("Index of element - 100: " + numbers.IndexOf(100));
            Console.WriteLine("Contains - 3: " + numbers.Contains(3));
            Console.WriteLine("Min: " + numbers.Min());
            Console.WriteLine("Max: " + numbers.Max());
            Console.WriteLine();

            GenericList <string> names = new GenericList <string>();

            names.Add("Pesho");
            names.Add("Gosho");
            names.Add("Ivan");

            Console.WriteLine("List: " + names);
            names.InsertElementAt("Mariika", 3);
            Console.WriteLine("List after InsertElementAt: " + names);
            names.RemoveElementAtIndex(2);
            Console.WriteLine("List after RemoveElementAtIndex: " + names);
            Console.WriteLine("Element at index - 2: " + names.ElementAtIndex(2));
            Console.WriteLine("Index of element - Pesho: " + names.IndexOf("Pesho"));
            Console.WriteLine("Contains - Ivan: " + names.Contains("Ivan"));
            Console.WriteLine();

            Console.WriteLine(names.Version());
        }
Esempio n. 3
0
        static void Main()
        {
            GenericList <int> listOfIntegers = new GenericList <int>();

            listOfIntegers.Add(28);
            listOfIntegers.Add(-4);
            listOfIntegers.Add(91);
            Console.WriteLine("listOfIntegers at this moment: " + listOfIntegers);
            Console.WriteLine("Element at index 1 is: " + listOfIntegers.AccessElementByIndex(1));
            listOfIntegers.RemoveElementByIndex(2);
            Console.WriteLine("listOfIntegers after removing the element at index 2: " + listOfIntegers);
            listOfIntegers.Add(3214);
            listOfIntegers.Add(-144);
            Console.WriteLine("listOfIntegers after adding some elements: " + listOfIntegers);
            listOfIntegers.InsertElementAtGivenPosition(2, 555);
            Console.WriteLine("listOfIntegers at this moment: " + listOfIntegers);
            listOfIntegers[0] = -1234;
            Console.WriteLine("listOfIntegers at this moment: " + listOfIntegers);
            Console.WriteLine("Element 555 is at index: " + listOfIntegers.FindElementIndexByGivenValue(555));
            Console.WriteLine("Element 3214 is at index: " + listOfIntegers.FindElementIndexByGivenValue(3214));
            Console.WriteLine("Element -11111 is at index: " + listOfIntegers.FindElementIndexByGivenValue(-11111));
            Console.WriteLine("The list contains the value -144: " + listOfIntegers.ContainsValue(-144));
            listOfIntegers.Clear();
            Console.WriteLine("listOfIntegers after clear command: " + listOfIntegers);

            Console.WriteLine();
            Type type = typeof(GenericList <>);

            object[] allAttributes = type.GetCustomAttributes(false);
            foreach (var version in allAttributes)
            {
                VersionAttribute v = version as VersionAttribute;
                if (v != null)
                {
                    Console.WriteLine("Version of GenericList<>: " + v.Version);
                }
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var list = new GenericList <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
            };

            list.Version();
            Console.WriteLine(list.Count);
            list.Add(1);
            Console.WriteLine(list.Count);
            Console.WriteLine(list.Min());
            Console.WriteLine(list.Max());
            Console.WriteLine(list.Contains(6));
            Console.WriteLine(list.FindIndex(17));
            list.Insert(21341, 12);
            Console.WriteLine(list);
            list.Remove(0);
            Console.WriteLine(list);
            list[2] = 23;
            Console.WriteLine(list);
            list.Clear();
            Console.WriteLine(list);
        }
Esempio n. 5
0
        private static void Main()
        {
            GenericList <int> list = new GenericList <int>();

            list.Add(5);
            list.Add(3);

            list.InsertAtPos(9, 4);

            Console.WriteLine(list[0].ToString());
            Console.WriteLine(list[1].ToString());
            Console.WriteLine(list[2].ToString());

            int indexOfFive = list.FindFirstIndexOf(3);

            Console.WriteLine(indexOfFive.ToString());

            Console.WriteLine(list.ToString());

            Console.WriteLine(list.Min(3, 4));
            Console.WriteLine(list.Max(3, 4));

            list.Clear();
            Console.WriteLine(list.ToString());
            //VersionAttribute version = new VersionAttribute(2, 11);
            //ShowMessageBox(0,"Version: " + version.Major.ToString() + "." + version.Minor.ToString(), "Program information", 0);

            Type type = typeof(MainClass);

            object[] allAttributes = type.GetCustomAttributes(false);
            foreach (VersionAttribute attr in allAttributes)
            {
                Console.WriteLine(
                    "This class has version {0}.{1} ", attr.Major, attr.Minor);
            }
        }
Esempio n. 6
0
        public static void Main()
        {
            GenericList <int> genericList = new GenericList <int>()
            {
                1, 2, 3, 100
            };

            Print(genericList, "New GenericList");

            // Clear
            genericList.Clear();
            Print(genericList, "Clear");

            // Add
            genericList.Add(1);
            genericList.Add(3);
            genericList.Add(8);
            genericList.Add(69);
            Print(genericList, "Add // 1, 3, 8, 69");

            // Insert on specific index
            genericList.Insert(4, 5);
            Print(genericList, "Insert at index // 0 -> 5");

            // Remove by index
            genericList.RemoveAt(4); // will remove 69
            Print(genericList, "RemoveAt // index 4");

            // Add range
            genericList.AddRange(100, 200, 300, 400);
            Print(genericList, "Add range // 100, 200, 300, 400");

            // Add on specific index
            genericList[0] = 69;
            Print(genericList, "Insert at index // 0");

            // Print element that is on specific index
            Print(genericList[0], "Show by index // 0");

            // Get item's index, if item not presented returns -1
            Print(genericList.GetIndex(100), "Find item's index // 100");
            Print(genericList.GetIndex(1000), "Find item's index // 1000");

            // Contains
            Print(genericList.Contains(300), "Check if collaction contains // 300");
            Print(genericList.Contains(3000), "Check if collaction contains // 3000");

            // Show total capacity
            Print(genericList.Capacity, "Collection capacity");

            // Show size
            Print(genericList.Size, "Collection size");

            // Minimum, extension generic method
            genericList.Add(-5);
            Print(genericList.Minimum(), "Find min element");

            // Maximum, extension generic method
            Print(genericList.Maximum(), "Find max element");

            // Foreaching through elements
            Console.WriteLine("Foreaching through elements");
            foreach (var item in genericList)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();

            Console.WriteLine(genericList.Average());

            // New generic list of DateTime
            IGenericList <DateTime> dates = new GenericList <DateTime>();

            dates.Add(DateTime.MaxValue);
            dates.Add(DateTime.Now);

            Print(dates, "Print dates");
        }
Esempio n. 7
0
        static void Main()
        {
            var list = new GenericList <int>(4);

            list.Add(22);
            list.Add(33);
            list.Add(1);
            list.Add(16);
            list.Add(8);
            list.Add(21);
            list.Add(3);
            list.Print();

            list.Insert(0, 9);
            list.Print();

            var index = list.IndexOf(33);

            Console.WriteLine(index);

            var tr = list.Contains(16);

            Console.WriteLine(tr);

            var fl = list.Contains(102);

            Console.WriteLine(fl);

            var find = list.FindIndex(x => x == 1);

            Console.WriteLine(find);

            list.Remove(33);
            list.Print();

            //exception
            //list.Remove(332);
            //list.Print();

            list.RemoveAt(1);
            list.Print();

            var min = list.Min();
            var max = list.Max();

            Console.WriteLine(min);
            Console.WriteLine(max);

            list.Clear();
            list.Print();

            //Problem 4. Generic List Version

            var typeOfList = typeof(GenericList <>);
            var atributes  = typeOfList.GetCustomAttributes(false);

            foreach (VersionAttribute attribute in atributes)
            {
                Console.WriteLine("Version " + attribute.Version);
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            var customAttributes = typeof(GenericList <>).GetCustomAttributes(typeof(VersionAttribute), true);

            Console.WriteLine("This GenericList<T> class's version is {0}", customAttributes[0]);
            //INT LIST
            GenericList <int> intList = new GenericList <int>(1);

            //1-5
            intList.Add(1);
            intList.Add(2);
            intList.Add(3);
            intList.Add(4);
            intList.Add(5);
            Console.WriteLine("1-5 LIST:");
            Console.WriteLine(intList);

            //Insert
            intList.Insert(5, 6);
            intList.Insert(0, -1);
            intList.Insert(4, 3);
            Console.WriteLine("After Instert:");
            Console.WriteLine(intList);

            //Time for some removal
            intList.Remove(5);
            intList.Remove(6);
            Console.WriteLine("After removal:");
            Console.WriteLine(intList);

            //Remove comment to clear list!
            //intList.Clear();

            //Access index
            Console.WriteLine("Print the list with by accessing elements' index:");
            Console.WriteLine("Number of elements: {0}", intList.Count);
            for (int i = 0; i < intList.Count; i++)
            {
                int element = intList[i];
                Console.WriteLine(element);
            }

            Console.WriteLine("Smallest element is: " + intList.Min());
            Console.WriteLine("Max element is: " + intList.Max());

            Console.WriteLine();

            GenericList <string> stringList = new GenericList <string>();

            stringList.Add("C#");
            stringList.Add("Java");
            stringList.Add("PHP");
            stringList.Add("SQL");
            Console.WriteLine("Number of elements: {0}", stringList.Count);
            for (int i = 0; i < stringList.Count; i++)
            {
                string element = stringList[i];
                Console.WriteLine(element);
            }

            Console.WriteLine("Smallest element is: " + stringList.Min());
            Console.WriteLine("Max element is: " + stringList.Max());
        }