Esempio n. 1
0
        static void Main()
        {
            GenericList <int> integerList = new GenericList <int>();

            Console.WriteLine(integerList.Capacity); // 16
            Console.WriteLine(integerList.Count);    // 0

            integerList.Add(1);
            integerList.Add(2);
            integerList.InsertAt(1, 3);
            Console.WriteLine(integerList.Capacity);   // 16
            Console.WriteLine(integerList.Count);      // 3
            Console.WriteLine(integerList);            // {1, 3, 2}
            Console.WriteLine(integerList.IndexOf(1)); // 0
            Console.WriteLine(integerList.Exists(0));  // False
            Console.WriteLine(integerList.Exists(2));  // True

            integerList.RemoveAt(0);
            Console.WriteLine(integerList);                         // {3, 2}
            Console.WriteLine(integerList.IndexOf(1));              // -1
            Console.WriteLine(GenericList <int> .Min(integerList)); // 2
            Console.WriteLine(GenericList <int> .Max(integerList)); // 3

            integerList.InsertAt(12, 7);
            Console.WriteLine(integerList.Count); // 13
            Console.WriteLine(integerList);       // {3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7}

            System.Reflection.MemberInfo info = typeof(GenericList <>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }
        }
Esempio n. 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
        }
Esempio n. 3
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();
        }
Esempio n. 4
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. 5
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);
            }
        }