static void Main() { GenericList<int> list = new GenericList<int>(5); list.Add(1); list.Add(3); list.Add(5); list.Add(7); list.Add(9); //Console.WriteLine(list); //list.FindElementWithValue(2); //list.FindElementWithValue(3); //Console.WriteLine(); //list.RemoveElementAtIndex(4); //Console.WriteLine(list); //list.InsertElementAtIndex(1, 2); //list.InsertElementAtIndex(5, 1); //Console.WriteLine(list); //list.ClearList(); //Console.WriteLine(list); // Min() and Max() Test Console.WriteLine(list.Min<int>()); Console.WriteLine(list.Max<int>()); }
public static void Main() { GenericList<int> a = new GenericList<int>(); a.Add(15); a.Add(20); a.Add(30); a.Add(40); a.Add(55); a.Add(60); a.Add(70); a.Add(100); a.Add(100); Console.WriteLine(a.Capacity); a.Add(15); a[2] = 500; Console.WriteLine(a); Console.WriteLine(a.IndexOf(30)); Console.WriteLine(a.Contains(500)); a.InsertAt(10, 59); a.InsertAt(11, 59); a.InsertAt(12, 59); a.InsertAt(13, 59); a.InsertAt(14, 59); a.InsertAt(15, 59); a.InsertAt(16, 59); Console.WriteLine(a); Console.WriteLine(a.Capacity); Console.WriteLine(a.IsEmpty); Console.WriteLine(a.Min()); Console.WriteLine(a.Max()); a.Clear(); }
static void Main(string[] args) { var listtt = new List<int>(); GenericList<int> myList = new GenericList<int>(10); //ADD myList.Add(1); myList.Add(2); myList.Add(3); Console.WriteLine(myList.ToString()); Console.WriteLine("Insert element"); //INSERT AT GIVEN POSITION myList.Insert(3, 50); myList.Insert(3, 60); Console.WriteLine(myList.ToString()); Console.WriteLine("Find element:"); //FIND CERTAINT ELEMENT AT WHAT INDEXES EXISTS myList.Find(25); Console.WriteLine("Remove element:"); //REMOVE AT CERTAIN INDEX myList.Remove(2); Console.WriteLine(myList.ToString()); Console.WriteLine("Find maximum"); //FIND MAX Console.WriteLine(myList.Max()); Console.WriteLine("Find minimum"); //FIND MIN Console.WriteLine(myList.Max()); //CLEAR ALL Console.WriteLine("Clear all"); myList.Clear(); Console.WriteLine(myList.ToString()); }
static void Main(string[] args) { Console.WriteLine(typeof(GenericList<>).GetCustomAttribute(typeof(Ver))); GenericList<string> list = new GenericList<string>(); GenericList<Point2D> list2 = new GenericList<Point2D>(); list2.Add(new Point2D(5, 3)); list2.Add(new Point2D(6, 4)); list.Add("az"); list.Add("ti"); list.Add("toj"); list.Add("tq"); list.Insert("to",1); list.Remove(3); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i]); } Console.WriteLine(Environment.NewLine); Console.WriteLine(list.FindIndexOf("toj")); Console.WriteLine(list); Console.WriteLine(list.Contains("tq")); Console.WriteLine(list.Max()); Console.WriteLine(list2.Max()); Console.WriteLine(list2.Contains(new Point2D(5, 3))); Console.WriteLine(list2.Contains(new Point2D(5, 2))); }
public static void Main() { GenericList<int> list = new GenericList<int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Add(5); Console.WriteLine("Making a new list:\n " + list); Console.WriteLine("Inserting a number 6 at position 2!"); list.Insert(2, 6); Console.WriteLine(list); Console.WriteLine("The position of number 3 is {0}!", list.IndexOf(3)); Console.WriteLine("Remove an element on position 3."); list.RemoveAt(3); Console.WriteLine(list); Console.WriteLine("The MIN element in the list is {0}", list.Min()); Console.WriteLine("The MAX element in the list is {0}", list.Max()); list.Clear(); Console.WriteLine("The list after list.Clear()! \n" + list); //Console.WriteLine(list.Min()); }
public static void Main() { //5 Write a generic class GenericList<T> that keeps a list of elements of some parametric type T. //Keep the elements of the list in an array with fixed capacity which is given as parameter in the class constructor. //Implement methods for adding element, accessing element by index, removing element by index, //inserting element at given position, clearing the list, finding element by its value and ToString(). //Check all input parameters to avoid accessing elements at invalid positions. GenericList<int> testList = new GenericList<int>(3); testList.Add(2); testList.Add(3); testList.Add(4); testList.Remove(3); //6 Implement auto-grow functionality: when the internal array is full, //create a new array of double size and move all elements to it. GenericList<char> growList = new GenericList<char>(2); testList.Add('a'); testList.Add('b'); testList.Add('c'); testList.Add('d'); testList.Add('e'); //7 Create generic methods Min<T>() and Max<T>() for finding the minimal and maximal element in the GenericList<T>. //You may need to add a generic constraints for the type T. GenericList<int> comearableList = new GenericList<int>(); comearableList.Add(1); comearableList.Add(4); comearableList.Add(1321); Console.WriteLine("The biggest element in Comearable List is:"); Console.WriteLine(comearableList.Max()); }
static void Main(string[] args) { //Printing - Genreic List Version Atribute - Problem.04 var result = typeof(GenericList<int>).GetCustomAttributes(true).First(); Console.WriteLine(result); GenericList<Car> cars = new GenericList<Car>(); Car ferrari = new Car("Ferrari", "F360", 155000); cars.Add(ferrari); Car alfa = new Car("Alfa", "Spider", 95000); cars.Add(alfa); Car mercedes = new Car("Mercedes", "AMG SL65", 135000); cars.Add(mercedes); Car lada=new Car("Lada","1500",2500); Console.WriteLine(cars[0]); Console.WriteLine(cars[1]); Console.WriteLine(cars[2]); Console.WriteLine("List size {0}",cars.Size); Console.WriteLine("List capacity {0}",cars.Capacity); cars.InsertAt(lada, 2); Console.WriteLine(cars[2]); Console.WriteLine("List size {0}", cars.Size); Console.WriteLine(cars.Contains(ferrari)); }
static void Main() { string decorationLine = new string('-', 80); Console.Write(decorationLine); Console.WriteLine("***Creating and clearing lists of some type. Adding, removing, accessing, finding, inserting elements.***"); Console.Write(decorationLine); Console.WriteLine("---Creating an empty list of strings---"); GenericList<string> list = new GenericList<string>(); Console.WriteLine("Empty list count: " + list.Count); Console.WriteLine("Empty list capacity: " + list.Capacity); Console.WriteLine("\n---Adding some elements to the list---"); for (int count = 0; count < 16; count++) { list.Add("element " + (count + 1)); } Console.WriteLine("The elements of the list are: " + list.ToString()); Console.WriteLine("After adding some elements list count: " + list.Count); Console.WriteLine("After adding some elements list capacity: " + list.Capacity); Console.WriteLine("\n---Printing elements at specific indexes---"); Console.WriteLine("Printing element with index 5: " + list[5]); Console.WriteLine("Printing element with index 0: " + list[0]); Console.WriteLine("\n---Removing some elements from the list---"); list.RemoveAt(5); list.RemoveAt(0); list.RemoveAt(12); Console.WriteLine("After removing elements from the list: " + list.ToString()); Console.WriteLine("Current list count: " + list.Count); Console.WriteLine("\n---Inserting some elements to the list---"); list.InsertAt("string 5", 5); list.InsertAt("appear", list.Count - 1); list.InsertAt("string11", list.Count); Console.WriteLine("The new list is: " + list.ToString()); Console.WriteLine("The new list count is: " + list.Count); Console.WriteLine("\n---Finding specific elements from the list---"); Console.WriteLine("The index of 'element 9' is: " + list.Find("element 9")); Console.WriteLine("The index of 'element 111' is: " + list.Find("element 111")); Console.WriteLine("\n---Finding the maximal and the minimal element in the list---"); Console.WriteLine("The minimal element in the list is: " + list.Min()); Console.WriteLine("The maximal element in the list is: " + list.Max()); Console.WriteLine("\n---Clearing the list---"); list.Clear(); Console.WriteLine("List count after clearing the list: " + list.Count); Console.WriteLine("List capacity after clearing the list: " + list.Capacity); // We cannot use Min() and Max() on "test" because it doesn't implement IComparable<> GenericList<Point2D> test = new GenericList<Point2D>(); test.Add(new Point2D(5, 6)); test.Add(new Point2D(-2, 1)); test.Add(new Point2D(-12, -11)); //test.Min(); //test.Max() }
public void TestMethod5() { GenericList<int> nov = new GenericList<int>(1); nov.Add(0); nov.Add(0); nov.Add(0); nov.InsertAt(2, 3); nov.Add(0); nov.Add(0); nov.InsertAt(3, 0); nov.Add(0); nov.Add(0); nov.Add(0); nov.Add(0); nov.Add(0); nov.Add(0); nov.Add(0); nov.Add(0); var expected = new GenericList<int>(); expected.Add(0); expected.Add(0); expected.Add(3); expected.Add(0); expected.Add(0); Assert.AreNotEqual(expected.Length, nov.Length); }
static void Main() { GenericList<Decimal> testGenList = new GenericList<decimal>(); testGenList.Add(125.53M); testGenList.Add(123); testGenList.Add(100); testGenList.Add(1000); testGenList.Add(10000); Console.WriteLine(testGenList.ToString()); Console.WriteLine(testGenList.Find(100)); Console.WriteLine(testGenList.Access(1)); Console.WriteLine(testGenList.Capacity); testGenList.Insert(0, 0); testGenList.Insert(5, 3); testGenList.Remove(testGenList.Count - 1); Console.WriteLine(testGenList.ToString()); testGenList.Insert(16.16M, testGenList.Count - 1); testGenList.Insert(17.17M, testGenList.Count - 1); testGenList.Insert(18.18M, testGenList.Count - 1); testGenList.Insert(19.19M, testGenList.Count - 1); Console.WriteLine(testGenList.ToString()); Console.WriteLine(testGenList.Max()); testGenList.Remove(testGenList.Find(testGenList.Max())); Console.WriteLine(testGenList.ToString()); Console.WriteLine(testGenList.Max()); Console.WriteLine(testGenList.Min()); testGenList.Remove(0); Console.WriteLine(testGenList.Min()); testGenList.Clear(); Console.WriteLine(testGenList.ToString()); }
static void Main() { GenericList<int> list = new GenericList<int>(2); list.Add(1); list.Add(13); list.Add(12); Console.WriteLine("Generic list contains: {0}",list); Console.WriteLine("Second element of the list is {0}", list[2]); Console.WriteLine("Smallest element in the list is {0}", list.Min<int>()); Console.WriteLine("Biggest element in the list is {0}", list.Max<int>()); Console.Write("Please enter a value to search: "); int valueToSearch = int.Parse(Console.ReadLine()); Console.WriteLine("Position: {0}", list.Find(valueToSearch)); list.Clear(); Console.WriteLine("List Cleared -> {0}", list); }
public static void Main() { GenericList<int> list = new GenericList<int>(4); Console.WriteLine("Add , auto-grow and ToString() test"); Console.WriteLine(); // Testing add method and auto-grow for (int i = 1; i <= 20; i++) { list.Add(i); } Console.WriteLine(list.ToString()); AddSeparator(); // Add 100 on position 5 Console.WriteLine("Test insert at position (insert 100 on position 5)"); Console.WriteLine(); list.Add(100, 5); Console.WriteLine(list.ToString()); AddSeparator(); // Test min and max Console.WriteLine("Min --> {0}", list.Min()); Console.WriteLine("Max --> {0}", list.Max()); AddSeparator(); // Indexer test Console.WriteLine("Indexer test:"); Console.WriteLine("list[5] --> {0}", list[5]); AddSeparator(); }
static void Main() { GenericList<int> myList = new GenericList<int>(); myList.Add(5); myList.Add(1); myList.Add(3); myList.Add(8); Console.WriteLine(myList); myList.Remove(2); Console.WriteLine(myList); myList.Insert(12, 2); Console.WriteLine(myList); myList.FindElementIndex(1); myList.FindElementIndex(17); Console.WriteLine(GenericList<int>.Max(5, 12)); Console.WriteLine(GenericList<int>.Min(123,3)); bool test = myList.Contains(8); bool anotherTest = myList.Contains(26); Console.WriteLine(test + " " + anotherTest); }
static void Main() { GenericList<int> test = new GenericList<int>(5); test.Add(56); test.Add(56); test.Add(56); test.Add(56); test.Add(56); test.Add(56); GenericList<string> test2 = new GenericList<string>(10); test2.Add("asdasda"); test2.Add("sadasdsd"); test2.RemoveElement(0); Console.WriteLine(test2.ElementByIndex(0)); test.InsertAt(2, 57); Console.WriteLine(test.FindElementByValue(57)); int t = GenericList<GenericList<string>>.Min<int>(67, 68); Console.WriteLine(t); //GenericList<int> testList = new GenericList<int>(); //GenericList<string> testList2 = new GenericList<string>(); //testList.Add(56); //Tuple<int, string> test = new Tuple<int, string>(5, "az"); //Console.WriteLine(test.Item2); //int a = 5; //int b = 6; //int min = Max<int>(a, b); //Console.WriteLine(min); }
static void Main(string[] args) { GenericList<int> test = new GenericList<int>(); Console.WriteLine(); test.Add(123); test.Add(1234); test.Add(12345); test.Add(123456); Console.WriteLine(test); test.Remove(2); test.Insert(11, 2); test.Insert(666, 0); Console.WriteLine(test); Console.WriteLine(test.Find(11)); Console.WriteLine(test.Contains(1234)); test.Add(-100); Console.WriteLine(test.Min()); Type type = test.GetType(); object[] allAttributes = type.GetCustomAttributes(false) .Where(x => x.GetType() == typeof(VersionAttribute)) .ToArray(); foreach (VersionAttribute attr in allAttributes) { Console.WriteLine(attr.Major + "." + attr.Minor); } }
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 }
static void Main() { GenericList<int> test = new GenericList<int>(10); for (int i = 0; i < test.Length; i++) { test.Add(i); } Console.WriteLine(test.ToString()); test.Remove(9); Console.WriteLine(test.ToString()); test.Insert(9, 9); Console.WriteLine(test); GenericList<int> newTest = new GenericList<int>(10); for (int i = 0; i < newTest.Length - 1; i++) { newTest.Add(i); } Console.WriteLine(newTest); newTest.Insert(10, 9); Console.WriteLine(newTest); newTest.Clear(); Console.WriteLine(newTest); Console.WriteLine(test[3]); GenericList<string> stringTest = new GenericList<string>(10); for (int i = 0; i < stringTest.Length - 2; i++) { stringTest.Add(i.ToString()); } Console.WriteLine(stringTest); stringTest.Add("huehuehueheuhe"); Console.WriteLine(stringTest); stringTest.Insert("Teehee", 9); Console.WriteLine(stringTest); }
static void Main(string[] args) { GenericList<int> list = new GenericList<int>(3); list.Add(0); list.Add(1); list.Add(2); //Insert at position 2 list.InsertAt(2,9); Console.WriteLine("The 2nd element is:{0}",list[2]); //Find the max value Console.WriteLine("Max value is:{0}", list.Max()); //Remove index 2 list.RemoveAt(2); Console.WriteLine(list[2]); Console.WriteLine("The 2nd element is:{0}", list[2]); //Find the min value Console.WriteLine("Min value is:{0}", list.Min()); //Clear the list list.Clear(); Console.WriteLine("The length of the list after it has been cleared:{0}", list.All.Length); }
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); } }
public static void Main() { Console.Title = "Problem 3. Generic "; GenericList<int> numbers = new GenericList<int>(); numbers.Add(5); numbers.Add(50); numbers.Add(500); numbers.Add(1000); Console.WriteLine(numbers.Max()); Console.WriteLine(numbers.Min()); Console.WriteLine(numbers.GetAtIndex(1)); numbers.Insert(1, 25); Console.WriteLine(numbers.IndexOf(50)); Console.WriteLine(numbers.Contains(5)); numbers.Remove(5); Console.WriteLine(numbers); numbers.Clear(); Console.WriteLine(numbers); Console.WriteLine(); Console.WriteLine("Problem 4. Generic List Version"); System.Reflection.MemberInfo info = typeof(GenericList<>); foreach (object attribute in info.GetCustomAttributes(false)) { Console.WriteLine(attribute); } }
static void Main() { GenericList<int> list = new GenericList<int>(); list.Add(0); list.Add(1); //Console.WriteLine(list[2]); list.Insert(1, 4); list[0] = 2; list[2] = 3; //list[3] = 3; Console.Write("Accessing by index (list[1]): "); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(list[1]); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("ToString(): "); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(list.ToString()); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Min<int>(): "); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(list.Min<int>()); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Max<int>(): "); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(list.Max<int>()); Console.ForegroundColor = ConsoleColor.Gray; }
static void Main() { var intList = new GenericList<int>(); intList.Add(1); intList.Add(2); intList.Add(3); intList.Add(4); intList.Add(5); Console.WriteLine("Number of elements: {0}", intList.Count); Console.WriteLine(intList); intList[4] = 133; Console.WriteLine(intList); intList.Remove(2); Console.WriteLine(intList); intList.Insert(0, 4); Console.WriteLine(intList); Console.WriteLine(intList.Find(133)); Console.WriteLine(intList.Contains(4)); Console.WriteLine("Max = " + intList.Max()); Console.WriteLine("Min = " + intList.Min()); intList.Clear(); Console.WriteLine("Elemets in List: " + intList.Count); Type type = typeof(GenericList<>); object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false); Console.WriteLine("GenericsList's version is {0}", ((VersionAttribute)allAttributes[0]).Version); }
public static void Main() { GenericList<int> myIntList = new GenericList<int>(4); myIntList.Add(1); myIntList.Add(3); myIntList.Insert(1, 2); Console.WriteLine("My int list: " + myIntList); Console.WriteLine("Max is: " + myIntList.Max()); Console.WriteLine("Min is: " + myIntList.Min()); Console.WriteLine(); GenericList<string> myStringList = new GenericList<string>(); myStringList.Add("Joro"); myStringList.Add("Ivan"); myStringList.Add("Barack Obama"); Console.WriteLine("My string list: " + myStringList); Console.WriteLine("Max is: " + myStringList.Max()); Console.WriteLine("Min is: " + myStringList.Min()); Console.WriteLine(); object[] versionAttributes = typeof(GenericList<string>).GetCustomAttributes(false); Console.WriteLine("Version is: " + versionAttributes[1]); }
static void Main() { GenericList<int> listInt = new GenericList<int>(); GenericList<string> listString = new GenericList<string>(60); listInt.Add(5); listInt.Add(6); listInt.Add(7); listInt.Add(8); listString.Add("Generic"); listString.Add("List"); int takeElement = listInt.ElementAt(0); // list.InsertAt(1, 5); // list.RemoveAt(0); // list.Clean(); // int index = list.GetIndex(5); // int capacity = list.Capacity; // int count = list.Count; int min = listInt.Min(); int max = listInt.Max(); string minString = listString.Min(); string maxString = listString.Max(); Console.WriteLine(listInt); Console.WriteLine(listString); }
static void Main() { GenericList<int> list = new GenericList<int>(3); GenericList<string> listNames = new GenericList<string>(2); listNames.Add("Pesho"); listNames.Add("Avan"); Console.WriteLine(listNames); Console.WriteLine(listNames.Min<string>()); list.Add(1); list.Add(2); list.Add(1); //list.RemoveElement(2); //list.Clear(); list.Insert(10, 0); list.Add(-3); list.Add(13); list.Add(3); list.TakeElement(1); Console.WriteLine(list); Console.WriteLine(list.FindElement(10)); list.FindElement(2); Console.WriteLine("Minimal value: " + list.Min<int>()); Console.WriteLine("Maximal value: " + list.Max<int>()); Console.WriteLine("Capacity: " + list.Capacity); Console.WriteLine("Count: " + list.Count); }
static void Main() { GenericList<int> testList = new GenericList<int>(); int chislo = 231; testList.Add(chislo); testList.Add(chislo); testList.InsertAtPosition(1, 5); testList.InsertAtPosition(1, 5); testList.Add(chislo + 9); int element = testList[0]; Console.WriteLine(element); testList.RemoveAtIndex(3); testList.InsertAtPosition(0, 124); //testList.Clear(); testList.FindElementByValue(421); testList.ToStringNew(); int min = testList.Min(); Console.WriteLine(min); int max = testList.Max(); Console.WriteLine(max); }
static void Main() { // Declare a list of type int GenericList<int> intList = new GenericList<int>(); intList.Add(1); intList.Add(2); intList.Add(3); 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(); // Declare a list of type string 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); } }
public static void Main() { IntegerList listOfIntegers = new IntegerList(5); Console.WriteLine(listOfIntegers.Count); listOfIntegers.Add(3); listOfIntegers.Add(4); listOfIntegers.Add(5); listOfIntegers.Add(1); Console.WriteLine("Count: " + listOfIntegers.Count); Console.WriteLine("Contains 2? " + listOfIntegers.Contains(2)); Console.WriteLine("Contains 4? " + listOfIntegers.Contains(4)); Console.WriteLine("Element at 2: " + listOfIntegers.GetElement(2)); Console.WriteLine("Element at 3: " + listOfIntegers.GetElement(3)); Console.WriteLine("Index of 7: " + listOfIntegers.IndexOf(7)); Console.WriteLine("Index of 5: " + listOfIntegers.IndexOf(5)); Console.WriteLine("Remove 5: " + listOfIntegers.Remove(5)); Console.WriteLine("Index of 5: " + listOfIntegers.IndexOf(7)); Console.WriteLine("Contains 5: " + listOfIntegers.Contains(5)); Console.WriteLine("Count: " + listOfIntegers.Count); Console.WriteLine("Element at 2: " + listOfIntegers.GetElement(2)); Console.WriteLine("Remove at 2: " + listOfIntegers.RemoveAt(2)); Console.WriteLine("Element at 1: " + listOfIntegers.GetElement(1)); Console.WriteLine("Count: " + listOfIntegers.Count); Console.WriteLine("Remove 5: " + listOfIntegers.Remove(5)); listOfIntegers.Clear(); Console.WriteLine(listOfIntegers.Count); //GenericList IGenericList<string> stringList = new GenericList<string>(); stringList.Add("Hello"); stringList.Add("World"); stringList.Add("!"); /* Console.WriteLine(stringList.Count); Console.WriteLine(stringList.Contains("Hello")); Console.WriteLine(stringList.IndexOf("Hello")); Console.WriteLine(stringList.GetElement(1)); */ foreach (string value in stringList) { Console.WriteLine(value); } /* IGenericList<double> doubleList = new GenericList<double>(2); doubleList.Add(0.2); doubleList.Add(0.7); Console.WriteLine(doubleList.Count); Console.WriteLine(doubleList.Contains(0.2)); Console.WriteLine(doubleList.IndexOf(0.7)); doubleList.Add(0.3); Console.WriteLine(doubleList.GetElement(2)); doubleList.Add(0.9); Console.WriteLine(doubleList.Count); */ }
public static void Main(string[] args) { //test GenericList Console.WriteLine("Test \"GenericList\""); GenericList<int> list = new GenericList<int>(5); int length = list.Capacity; for (int i = 0; i < length; i++) { list.Add(i + 5); } Console.WriteLine("list -> element at index 1 = {0}", list.GetElement(1)); Console.WriteLine(); Console.WriteLine("list -> {0}", list); Console.WriteLine(); list.InsertElementAtIndex(3, 7); list.InsertElementAtIndex(3, 7); list.InsertElementAtIndex(3, 7); list.InsertElementAtIndex(3, 7); list.InsertElementAtIndex(3, 7); list.InsertElementAtIndex(3, 7); list.InsertElementAtIndex(3, 7); Console.WriteLine("list -> {0}", list); Console.WriteLine(); list.Add(7); Console.WriteLine("list -> {0}", list); Console.WriteLine(); list.RemoveElementAtIndex(3); list.RemoveElementAtIndex(3); list.RemoveElementAtIndex(3); list.RemoveElementAtIndex(3); list.RemoveElementAtIndex(3); list.RemoveElementAtIndex(3); list.RemoveElementAtIndex(list.Count - 1); Console.WriteLine("list -> {0}", list); Console.WriteLine(); Console.WriteLine("find index of value 4 -> {0}", list.FindByValue(4)); Console.WriteLine("list -> {0}", list); Console.WriteLine(); Console.WriteLine("list min-element -> {0}", list.Min()); Console.WriteLine("list max-element -> {0}", list.Max()); Console.WriteLine(); Console.WriteLine("Clear list:"); list.Clear(); Console.WriteLine("list -> {0}", list); Console.WriteLine(); }
static void Main() { var doubleList = new GenericList<double>(); doubleList.Add(5.5); doubleList.Add(6.9); doubleList.Add(6.4); doubleList.Add(6.7); doubleList.Add(5.6); int count = doubleList.Count; double max = doubleList.Max(); double min = doubleList.Min(); Console.WriteLine(doubleList); Console.WriteLine("Max: {0}; Min: {1}; Count: {2}", max, min, count); doubleList.Remove(6.4); doubleList.Remove(5.5); doubleList.RemoveAt(1); count = doubleList.Count; max = doubleList.Max(); min = doubleList.Min(); Console.WriteLine(doubleList); Console.WriteLine("Max: {0}; Min: {1} Count: {2}", max, min, count); doubleList.Version(); doubleList.Clear(); bool isEmpty = doubleList.isEmpty; Console.WriteLine(isEmpty); Console.WriteLine(doubleList); var stringList = new GenericList<string>(); stringList.Add("Kircho"); stringList.Add("Jecho"); stringList.Add("Mecho"); stringList.Add("Vulcho"); bool jecho = stringList.Contais("Jecho"); bool nencho = stringList.Contais("Nencho"); string who = stringList.ElementOf(0); int index = stringList.IndexOf("Vulcho"); string maxString = stringList.Max(); Console.WriteLine(stringList); Console.WriteLine("jecho: {0} \nnencho: {1} \nElement of 0 index: {2} \nIndex of Vulcho: {3} \nMax: {4}" , jecho, nencho, who, index, maxString); string indexer = stringList[3]; Console.WriteLine(indexer); stringList.Insert("Gocho",2); Console.WriteLine(stringList[2]); stringList.Version(); }
public void TestMethod4() { GenericList <int> nov = new GenericList <int>(1); nov.Add(0); nov.Add(0); nov.Add(0); nov.InsertAt(2, 3); nov.InsertAt(3, 0); var expected = new GenericList <int>(); expected.Add(0); expected.Add(0); expected.Add(3); expected.Add(0); expected.Add(0); Assert.AreEqual(expected.Count, nov.Count); }
public void TestMethod2() { GenericList <int> nov = new GenericList <int>(3); nov.Add(0); nov.Add(0); nov.Add(0); nov.InsertAt(2, 3); nov.InsertAt(3, 0); var expected = new GenericList <int>(5); expected.Add(0); expected.Add(0); expected.Add(3); expected.Add(0); expected.Add(0); Assert.AreEqual(expected.ToString(), nov.ToString()); }
public void Execute() { var book = new Book { ISBN = "123", Title = "C#", Price = 50.29f }; var books = new GenericList <Book>(); books.Add(book); books.Add(new Book()); var dictionary = new GenericDictionary <string, Book>(); dictionary.Add("1234", new Book()); var number = new Generics.Nullable <int>(); Console.WriteLine($"Has value ? {number.HasValue}"); Console.WriteLine($"Value: {number.GetValueOrDefault()}"); }
static void Main(string[] args) { var listOfIntegers = new Integerlist(5); ListExample(listOfIntegers); /* * var polje = new Integerlist(4); * polje.Add(3); * polje.Add(4); * polje.Add(7); * polje.Add(6); * polje.Remove(7); * polje.Add(2); * polje.Add(8); * polje.Remove(4); * * Console.WriteLine(polje.Contains(1)); //false * polje.GetElement(4); //0 * Console.WriteLine("\nNumber of elements" + " " + polje.Count); //4 * polje.print(); //3 6 2 8 0 0 0 0 * Console.WriteLine(polje.Clear()); //True * */ IGenericList <string> stringList = new GenericList <string>(); stringList.Add(" Hello "); stringList.Add(" World "); stringList.Add("!"); foreach (string value in stringList) { Console.WriteLine(value); } IEnumerator <string> enumerator = stringList.GetEnumerator(); while (enumerator.MoveNext()) { string value = (string)enumerator.Current; Console.WriteLine(value); } Console.ReadLine(); }
static void Main(string[] args) { string input = Console.ReadLine(); GenericList <string> ourList = new GenericList <string>(); while (input != "END") { string[] commandInfo = input.Split(); switch (input) { case "Min": Console.WriteLine(ourList.Min()); break; case "Max": Console.WriteLine(ourList.Max()); break; case "Print": foreach (var item in ourList) { Console.WriteLine(item); } break; case "Sort": ourList = Sorter.Sort(ourList); break; } if (input.Contains("Add")) { string textToAdd = commandInfo[1]; ourList.Add(textToAdd); } else if (input.Contains("Remove")) { int indexToRemove = int.Parse(commandInfo[1]); ourList.Remove(indexToRemove); } else if (input.Contains("Contains")) { Console.WriteLine(ourList.Contains(commandInfo[1])); } else if (input.Contains("Swap")) { int firstIndex = int.Parse(commandInfo[1]); int secondIndex = int.Parse(commandInfo[2]); ourList.Swap(firstIndex, secondIndex); } else if (input.Contains("Greater")) { Console.WriteLine(ourList.Compare(commandInfo[1])); } input = Console.ReadLine(); } }
public void GenericList__Add_Single_Item_To_Empty_List() { var actual = new GenericList <int>(); int expected = 1; actual.Add(1); Assert.AreEqual(actual[0], expected); Assert.IsTrue(actual.Count == 1); }
public void Plus_ConcatenateListCheckFirstList() { GenericList <int> myList = new GenericList <int>(); GenericList <int> myListTwo = new GenericList <int>(); myList.Add(1); myList.Add(2); myList.Add(3); myListTwo.Add(4); myListTwo.Add(5); myListTwo.Add(6); GenericList <int> concatList = new GenericList <int>(); concatList = myList + myListTwo; Assert.AreEqual(2, concatList[1]); }
public void GetTest() { IGenericList <TodoItem> list = new GenericList <TodoItem>(); TodoItem ti = new TodoItem("a"); list.Add(ti); TodoRepository tr = new TodoRepository(list); Assert.AreEqual(ti, tr.Get(ti.Id)); }
public override string ToString() { GenericList <T> temp = new GenericList <T>(); for (int i = 0; i < this.count; i++) { temp.Add(this.elements[i]); } return(string.Join(", ", temp)); }
public void AddMoreItemsThanCapacityToList() { GenericList <int> _list = new GenericList <int>(); for (var i = 0; i < 15; i++) { _list.Add(i); } _list.Count.ShouldBe(15); }
public void Should_Add_integer_To_List() { //Arrange var numbers = new GenericList <int>(); //Act numbers.Add(2); //Assert Assert.AreEqual(2, numbers.GetByPosition(0)); }
static void Main() { GenericList<int> elements = new GenericList<int>(); // Empty list Console.WriteLine(elements); Console.WriteLine("Count: {0}", elements.Count); Console.WriteLine("Capacity: {0}", elements.Capacity); // Auto-grow functionality elements = new GenericList<int>(3); elements.Add(1); elements.Add(2); elements.Add(3); elements.Add(4); Console.WriteLine("\n" + elements); Console.WriteLine("Count: {0}", elements.Count); Console.WriteLine("Capacity: {0}", elements.Capacity); // Insert, RemoveAt elements.Clear(); elements.Insert(0, 4); elements.Insert(0, 3); elements.Insert(0, 2); elements.Insert(0, 1); elements.RemoveAt(0); elements.RemoveAt(elements.Count - 1); Console.WriteLine("\n" + elements); Console.WriteLine("Count: {0}", elements.Count); Console.WriteLine("Capacity: {0}", elements.Capacity); // Contains, IndexOf Console.WriteLine("\nContain element 2: {0}", elements.Contains(2)); Console.WriteLine("Index of element 3: {0}", elements.IndexOf(3)); // Max, Min Console.WriteLine("\nMin: {0}", elements.Min()); Console.WriteLine("Max: {0}", elements.Max()); }
public void Add_CountIncrementedAfterInsertion_CountIncrementedByOne() { GenericList <int> myList = new GenericList <int>(); int item = 5; myList.Add(item); Assert.AreEqual(1, myList.Count); }
public void Add_TestAddingItemToEmptyList_ItemAddedToIndexZero() { GenericList <int> myList = new GenericList <int>(); int item = 5; myList.Add(item); Assert.AreEqual(item, myList[0]); }
public void AddRestOfClothingItemsToArray() { //arrange GenericList <string> clothingList = new GenericList <string>(); int expected = 4; int actual; //act clothingList.Add("Shirt"); clothingList.Add("Pants"); clothingList.Add("Shoes"); clothingList.Add("Hat"); actual = clothingList.Count; //assert Assert.AreEqual(expected, actual); }
public void stringToStringTest() { GenericList <string> GenericList = new GenericList <string>(); string item = "Add Item"; GenericList.Add(item); string result = GenericList.ToString(); Assert.AreEqual(item, result); }
public void IntToStringTest() { GenericList <int> GenericList = new GenericList <int>(); int item = 1; GenericList.Add(item); string result = GenericList.ToString(); Assert.AreEqual(item, result); }
private static void GenericListInAction() { var int32GenList = new GenericList <int>(); var strGetList = new GenericList <string>(); var objGetList = new GenericList <object>(); int32GenList.Add(123); strGetList.Add("123"); objGetList.Add(123); objGetList.Add("123"); }
public void StringAddTest() { //Arrange GenericList <string> GenericList = new GenericList <string>(); string item = "This is my string"; //Act GenericList.Add(item); //Assert Assert.AreEqual(item, GenericList[0]); }
public void Start() { EventManager.instance.addEventListener(HUDEvent.ON_CHANGE_TO_FPS_VIEW, this.gameObject, "OnChangeViewToFps"); EventManager.instance.addEventListener(HUDEvent.ON_BACK_TO_OTHER_VIEW, this.gameObject, "OnBackToPreviousView"); EventManager.instance.addEventListener(AssetUIEvent.ON_CHANGE_TO_INSIDE_VIEW, this.gameObject, "OnEnterToFieldEvent"); m_currentViewState = new GenericList <KeyValuePair <GameViewState, LocationAndPosition> >(); LocationAndPosition locationEntity = new LocationAndPosition(InsideFieldLocation.None, null); m_currentViewState.Add(new KeyValuePair <GameViewState, LocationAndPosition>(GameViewState.FieldView, locationEntity)); }
static void Main(string[] args) { var numbers = new GenericList <int>(); numbers.Add(10); //System.Nullable var number = new Nullable <int>(5); System.Console.WriteLine("Has value ?" + number.HasValue); System.Console.WriteLine("value:" + number.GetValueOrDefault()); }
public void IntAddTest() { //Arrange GenericList <int> GenericList = new GenericList <int>(); int item = 5; //Act GenericList.Add(item); //Assert Assert.AreEqual(item, GenericList[0]); }
static void GenericSample() { GenericList <int> myList = new GenericList <int>(); myList.Add(10); GenericList <string> mySecodlist = new GenericList <string>(); mySecodlist.Add("Happy"); GenericList <TRex> myTrexList = new GenericList <TRex>(); myTrexList.Add(new TRex()); }
static void Main(string[] args) { GenericList <int> list1 = new GenericList <int>(); list1.Add(1); list1.Add(100); // Declare a list of type string. GenericList <string> list2 = new GenericList <string>(); list2.Add("Hello World"); list2.Add("Generics in C#"); // Declare a list of type ExampleClass. GenericList <ExampleClass> list3 = new GenericList <ExampleClass>(); list3.Add(new ExampleClass()); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here UpdateTitle(); Window.Position = new Point( (GraphicsDevice.DisplayMode.Width - Window.ClientBounds.Width) / 2, (GraphicsDevice.DisplayMode.Height - Window.ClientBounds.Height) / 2 ); var screenBounds = GraphicsDevice.Viewport.Bounds; PaddleBottom = new Paddle(GameConstants.PaddleDefaultWidth, GameConstants.PaddleDefaulHeight, GameConstants.PaddleDefaulSpeed); PaddleBottom.X = screenBounds.Width / 2.0f - PaddleBottom.Width / 2.0f; PaddleBottom.Y = screenBounds.Bottom - PaddleBottom.Height; PaddleTop = new Paddle(GameConstants.PaddleDefaultWidth, GameConstants.PaddleDefaulHeight, GameConstants.PaddleDefaulSpeed); PaddleTop.X = screenBounds.Width / 2.0f - PaddleBottom.Width / 2.0f; PaddleTop.Y = screenBounds.Top; Ball = new Ball(40, GameConstants.DefaultInitialBallSpeed, GameConstants.DefaultBallBumpSpeedIncreaseFactor); Ball.X = screenBounds.Width / 2.0f - Ball.Width / 2.0F; Ball.Y = screenBounds.Height / 2.0f - Ball.Height / 2.0F; Background = new Background(screenBounds.Width, screenBounds.Height); // Add our game objects to the sprites that should be drawn collection . SpritesForDrawList.Add(Background); SpritesForDrawList.Add(PaddleBottom); SpritesForDrawList.Add(PaddleTop); SpritesForDrawList.Add(Ball); Walls = new GenericList <Wall>(); Walls.Add(new Wall(null, -GameConstants.WallDefaultSize, 0, GameConstants.WallDefaultSize, screenBounds.Height)); Walls.Add(new Wall(null, screenBounds.Right, 0, GameConstants.WallDefaultSize, screenBounds.Height)); Goals = new GenericList <Wall>(); Goals.Add(new Wall(PaddleBottom, 0, screenBounds.Height, screenBounds.Width, GameConstants.WallDefaultSize)); Goals.Add(new Wall(PaddleTop, screenBounds.Top, -GameConstants.WallDefaultSize, screenBounds.Width, GameConstants.WallDefaultSize)); base.Initialize(); }
static void Main(string[] args) { GenericList <String> stringList = new GenericList <string>(); stringList.Add("abc"); stringList.Add("def"); stringList.Add("ghi"); stringList.Add("jkl"); stringList.Add("mno"); stringList.Add("pqr"); // foreach foreach (string value in stringList) { Console.WriteLine(value); } // foreach without the syntax sugar IEnumerator <string> enumerator = stringList.GetEnumerator(); while (enumerator.MoveNext()) { string value = (string)enumerator.Current; Console.WriteLine(value); } Console.ReadLine(); }
public static void Main() { var list = new GenericList <int>(20); list.Add(15); list.Add(22); list.Add(44); list.Add(-22); list.Add(-18); list.Add(int.MaxValue); // list after only adding elements in it -> 15, 22, 44, -22, -18, int.MaxValue Console.WriteLine(list); list.InsertAt(2, 1024); // list after inserting element at given index // 15, 22, 1024, 44, -22, -18, int.MaxValue Console.WriteLine(list); list.RemoveAt(0); // list after removing element at given index // 22, 1024, 44, -22, -18, int.MaxValue*/ Console.WriteLine(list); Console.WriteLine("list[2] = {0}", list[2]); Console.WriteLine("Max item: list[{0}] = {1}", list.GetElementIndex(list.Max()), list.Max()); Console.WriteLine("Min item: list[{0}] = {1}", list.GetElementIndex(list.Min()), list.Min()); Console.WriteLine("Capacity: {0}, Count: {1}", list.Capacity, list.ElementsCount); list.Clear(); Console.WriteLine("Count after clearing list: {0}", list.ElementsCount); // printed list after being cleared Console.WriteLine(list); }
public void Test3() { //arrange GenericList <double> items = new GenericList <double>(); double firstValue = 1.2; //act items.Add(1.2); double actualResult = items.items[0]; //assert Assert.Equal(firstValue, actualResult); }
public void Test4() { //arrange GenericList <bool> items = new GenericList <bool>(); bool firstValue = false; //act items.Add(1 == 2); bool actualResult = items.items[0]; //assert Assert.Equal(firstValue, actualResult); }
public void Test1() { //arrange GenericList <int> items = new GenericList <int>(); int firstValue = 1; //act items.Add(4); int actualResult = items.items[0]; //assert Assert.Equal(firstValue, actualResult); }