Пример #1
0
        static void Main(string[] args)
        {
            GenericList <string> list = new GenericList <string>();

            list.Add("Aa");
            list.Add("bbb");
            list.Add("ccc");
            list.Add("ddd");
            list.Add("eee");
            list.Add("fff");
            list.Add("ggg");
            list.Remove(2);
            list.Add("hjhjhh");
            list[11] = "jjj";
            list.InsertElementAtPosition("aaa", 1);
            list.Clear();
            list.Add("Aa");
            list.Add("bbb");
            list.Add("ccc");
            int index = list.IndexOf("ccc");

            list.InsertElementAtPosition("Rumen", 0);
            Console.WriteLine(list.ToString());
            Console.WriteLine(list.Max());



            Console.WriteLine();
        }
Пример #2
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
        }
Пример #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);
                }
            }
        }
Пример #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);
        }
Пример #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);
            }
        }
Пример #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");
        }
Пример #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);
            }
        }