예제 #1
0
        static void Main(string[] args)
        {
            var listGeneric = new GenericList <int>(5);

            listGeneric.AddElement(2);
            listGeneric.AddElement(6);
            listGeneric.AddElement(111);
            listGeneric.AddElement(1232);
            listGeneric.AddElement(44);

            var obj = listGeneric.RetunElementAtT(2);

            Console.WriteLine(obj);
        }
예제 #2
0
        static void Main()
        {
            var someList = new GenericList <double>(4);

            for (int i = 0; i < 5; i++)
            {
                someList.AddElement(i + 2.5);
            }

            someList.InsertAtIndex(0, -12.5);
            someList.InsertAtIndex(0, -16.3);

            for (int i = 0; i < someList.Count; i++)
            {
                Console.WriteLine(someList[i]);
            }

            someList.Clear();
            Console.WriteLine(someList.Count);
        }
예제 #3
0
        static void Main(string[] args)
        {
            // Generic list
            GenericList <string> Lista = new GenericList <string>(5);


            // Add element
            Lista.AddElement("Victor");
            Lista.AddElement("Ana");
            Lista.AddElement("Ioana");
            Lista.AddElement("Emilia");
            Lista.AddElement("Mina");
            Console.WriteLine(Lista);
            Console.WriteLine();

            // Access element by index
            var x = Lista[2];

            Console.WriteLine("Elementul de pe indexul {0} are valoarea {1}.", 2, x);
            Console.WriteLine();

            // Remove element by index
            Lista.RemoveElement(3);
            Console.Write("Dupa ce am sters elementul de pe indexul 3: ");
            Lista.Print();
            Console.WriteLine();

            // Insert element at given position
            Lista.InsertElement(2, "Robert");
            Console.Write("Dupa ce am inserat elementul Robert pe indexul 2: ");
            Console.WriteLine(Lista);
            Console.WriteLine();

            ////Clear the list
            //Lista.ClearList();
            //Console.WriteLine(Lista);
            //Console.WriteLine();

            // Find element by its value
            Console.WriteLine($"Elementul \"Robert\" se afla pe indexul {Lista.IndexOf("Robert")}.");
            Console.WriteLine();

            // ToString()
            Console.Write("Elementele sirului (folosind ToString) sunt: ");
            Console.WriteLine(Lista);
            Console.WriteLine();

            //         Problem 2. Auto-grow
            Lista.AutoGrow();
            Console.Write("AutoGrow: ");
            Console.WriteLine(Lista);
            Console.WriteLine();

            //       Problem 3. Min and Max
            var min = Lista.Min();

            Console.WriteLine("Minimul sirului este {0}.", min);
            Console.WriteLine();

            var max = Lista.Max();

            Console.WriteLine("Maximul sirului este {0}.", max);
            Console.WriteLine();


            Console.ReadKey();
        }