static void Main() { GenericList <int> list = new GenericList <int>(); //Add some numbers in the list list.Add(1); list.Add(2); list.Add(6); list.Add(8); //Insert number at given position in the list list.Insert(3, 1); Console.WriteLine("List: {0}", list); Console.WriteLine("Count: {0}", list.Count); Console.WriteLine("Capacity: {0}", list.Capacity); //Find a number and get its index in the list Console.WriteLine("The number 3 is at position {0} in the list.", list.Find(3)); //Get min and max numbers in the list Console.WriteLine("Max: " + list.Max()); Console.WriteLine("Min: " + list.Min()); //Clear the list list.Clear(); Console.WriteLine("List: {0}", list); }
static void Main(string[] args) { GenericList <int> intList = new GenericList <int>(3); Console.WriteLine("I added things in the list!"); intList.Add(1223); intList.Add(12); intList.Add(122); intList.Add(123344); Console.WriteLine(intList); Console.WriteLine("**********"); intList.Insert(123, 2); Console.WriteLine("After Inserting 123 in position 2 count from 0 : \n{0}", intList); Console.WriteLine("**********"); GenericList <string> stringList = new GenericList <string>(3); stringList.Add("kola"); stringList.Add("voda"); stringList.Add("kilo"); stringList.Add("far"); stringList.Add("doda"); Console.WriteLine("After Adding(and resizing) \n{0}", stringList); Console.WriteLine("**********"); stringList.Insert("az sum", 1); Console.WriteLine("After inserting az sum in position 1 count from 0: \n{0}", stringList); Console.WriteLine("The word kilo is in index: {0}", stringList.Find("kilo")); Console.WriteLine("This is the max element : {0}", stringList.Max()); Console.WriteLine("This is the min element : {0}", stringList.Min()); Console.WriteLine("**********"); stringList.Remove(2); Console.WriteLine("After removing element in position 2\n{0}", stringList); Console.WriteLine("**********"); stringList.Clear(); Console.WriteLine("After clearing(there is nothing because we clear the list ): {0} ", stringList); }
static void Main(string[] args) { GenericList <int> list = new GenericList <int>(); Point p1 = new Point(); Point p2 = new Point(); GenericList <Point> pList = new GenericList <Point>(); pList.Add(p1); pList.Add(p2); Console.WriteLine(pList[1]); Console.WriteLine(list.Count); Console.WriteLine(list.Capacity); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Add(5); Console.WriteLine(list.Count); Console.WriteLine(list.Capacity); list.Add(1); list.InsertAt(1, -50); list.RemoveAt(list.Count - 1); Console.WriteLine(list.ToString()); Console.WriteLine(list.IndexOf(5)); Console.WriteLine(pList.ToString()); Console.WriteLine(list.Max()); Console.WriteLine(list.Min()); //Console.WriteLine(pList.Max()); Console.WriteLine(list.Count); Console.WriteLine(list.Capacity); }
static void Main(string[] args) { GenericList <int> test = new GenericList <int>(3); test.Add(1); test.Add(2); test.Add(3); test.Add(4); test.Add(5); test.Insert(1, 33); test.Insert(0, 22); test.Insert(6, 66); Console.WriteLine("List:"); Console.WriteLine(test); Console.WriteLine("Min: {0}", test.Min()); Console.WriteLine("Max: {0}", test.Max()); test.RemoveAt(4); Console.WriteLine(test); Console.WriteLine("Position of '1' = {0}", test.IndexOf(1)); Console.WriteLine("Position of '33' = {0}", test.IndexOf(33)); }
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(); }