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); } }
static void Main(string[] args) { //предполагаме че типа е числен за да използвам за метода clear зануляване GenericList<string> Proba = new GenericList<string>(8); GenericList<decimal> Example = new GenericList<decimal>(18); Console.WriteLine(Example.ToString()); }
public void EmptyListDefaultCapacityTest() { GenericList<int> list = new GenericList<int>(); Assert.AreEqual((uint)0, list.Count); Assert.AreEqual((uint)4, list.Capacity); }
static void Main() { GenericList<int> list = new GenericList<int>(5); StringBuilder result = new StringBuilder(); list.Add(3); list.InsertAt(0, 2); list.InsertAt(0, 1); result.AppendLine(list.ToString()); result.AppendLine(String.Format("Count: {0}", list.Count)); result.AppendLine("--REMOVE AT INDEX 1--"); list.RemoveAt(1); result.AppendLine(list.ToString()); result.AppendLine(String.Format("Count: {0}", list.Count)); result.AppendLine(" MIN: " + list.Min()); result.AppendLine(" MAX: " + list.Max()); result.AppendLine("-----INDEX OF 3-----"); result.AppendLine(list.IndexOf(3).ToString()); result.AppendLine("-----INDEX OF 2-----"); result.AppendLine(list.IndexOf(2).ToString()); result.AppendLine("-----CLEAR LIST-----"); list.Clear(); result.AppendLine(list.ToString()); result.AppendLine(String.Format("Count: {0}", list.Count)); Console.WriteLine(result); }
static void Main(string[] args) { GenericList<string> genericList = new GenericList<string>(); genericList.Add("a"); genericList.Add("b"); genericList.Add("c"); Console.WriteLine(genericList); Console.WriteLine("Max = {0}, Min = {1}",genericList.Max(),genericList.Min()); Console.WriteLine("Remove b"); genericList.Remove("b"); Console.WriteLine(genericList); Console.WriteLine("genericList[0] = "+genericList.Access(0)); Console.WriteLine("index of c = "+genericList.FindIndex("c")); genericList.Clear(); genericList.Add("rom"); genericList.Add("mon"); genericList.Add("dom"); Console.WriteLine(genericList); Console.WriteLine("Insert zom (index = 1)"); genericList.Insert("zom",1); Console.WriteLine(genericList); Console.WriteLine(genericList.Contains("mon")); Console.WriteLine(genericList.Contains("aaa")); Type type = typeof(GenericList<>); object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false); foreach (VersionAttribute attr in allAttributes) { Console.WriteLine("This class's version is {0}.", attr.Version); } }
static void Main(string[] args) { GenericList<int> test = new GenericList<int>(1); test.Add(2); test.Add(45); test.Add(4); test.Add(50); test.Add(0); test.Add(-1000); Console.WriteLine(test); test.Remove(4); Console.WriteLine(test); test.Insert(0, 560); Console.WriteLine(test); Console.WriteLine(test.Find(123)); Console.WriteLine(test.Max()); Console.WriteLine(test.Min()); test.Clear(); Console.WriteLine(test); }
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 }
public static void Main() { GenericList<int> listTesting = new GenericList<int>(1); listTesting.AddElement(2); listTesting.AddElement(3); listTesting.AddElement(4); listTesting.AddElement(5); listTesting.AddElement(6); listTesting.AddElement(-1000); Console.WriteLine(listTesting); listTesting.RemoveElemAtIndex(4); Console.WriteLine(listTesting); listTesting.InsertElemAtIndex(0, 123); Console.WriteLine(listTesting); Console.WriteLine(listTesting.FindElemByValue(123)); Console.WriteLine(listTesting.Max()); Console.WriteLine(listTesting.Min()); listTesting.ClearList(); Console.WriteLine(listTesting); }
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()); }
public static void Main() { GenericList<int> myList = new GenericList<int>(); Console.WriteLine(); myList.Add(123); myList.Add(1293); myList.Add(11); myList.Add(12314); myList.Add(111111); Console.WriteLine(myList); myList.Remove(2); myList.Insert(11, 2); myList.Insert(666, 0); Console.WriteLine(myList); Console.WriteLine(myList.Find(11)); Console.WriteLine(myList.Contains(11121)); myList.Add(-100); Console.WriteLine(myList.Min()); Type type = myList.GetType(); object[] allAttributes = type.GetCustomAttributes(false) .Where(x => x.GetType() == typeof (VersionAttribute)) .ToArray(); foreach (VersionAttribute attr in allAttributes) { Console.WriteLine(attr.Major + "." + attr.Minor); } }
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(); }
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) { 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))); }
static void Main() { GenericList<int> testList = new GenericList<int>(5); testList.Add(5); testList.Add(45); testList.Add(18); testList.Add(66); testList.Add(22); testList.Add(6); testList.Add(2); testList.Add(9); testList.Add(10); Console.WriteLine("tstList.Count ->{0}",testList.Count); Console.WriteLine(testList.ToString()); testList.RemoveAt(3); Console.WriteLine("After removing an element:"); Console.WriteLine("tstList.Count ->{0}", testList.Count); Console.WriteLine(testList.ToString()); testList.InsertAt(3, 66); Console.WriteLine("After inserting an element:"); Console.WriteLine("tstList.Count ->{0}", testList.Count); Console.WriteLine(testList.ToString()); Console.WriteLine(); Console.WriteLine("searching for element:"); int position=testList.FindByValue(66); Console.WriteLine("The element is on position {0}", position); position = testList.Min(); Console.WriteLine("The Min Element in list is {0}",position); position = testList.Max(); Console.WriteLine("The Max Element in list is {0}",position); }
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() { GenericList<int> numbers = new GenericList<int>() { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 }; Console.WriteLine("Creating a GenericList with the numbers from 1 to 20 \n {0} \n", numbers); numbers.Remove(19); Console.WriteLine("Removing the 19th element \n {0} \n", numbers); numbers.Add(100); Console.WriteLine("Adding an element to the end of the GenericList \n {0} \n", numbers); numbers.Insert(30, 10); Console.WriteLine("Inserting an element on the 10th position \n {0} \n", numbers); numbers[3] = 9; Console.WriteLine("Changing the value of the 3rd index number \n {0} \n", numbers); Console.WriteLine("Trying to find number 4 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(4), numbers.Find(4)); Console.WriteLine("Trying to find number 80 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(80), numbers.Find(80)); Console.WriteLine("Min element: {0}, Max element: {1} \n", numbers.Min(), numbers.Max()); numbers.Clear(); Console.WriteLine("Cleared GenericList: \n {0} \n", numbers); Type type = typeof(GenericList<>); VersionAttribute attribute = (VersionAttribute)type.GetCustomAttributes(false).LastOrDefault(); Console.WriteLine("Version: " + attribute.Version); }
static void Main() { var list = new GenericList<int>(); //var list = new List<int>(); list.Add(15); list.Add(12); list.Add(48); list.Add(154); //list.Insert(4, 77); list.Add(13); list.Add(44); list.Add(78); list.Add(99); list.Insert(7, 33); Console.WriteLine(list); Console.WriteLine("Count: " + list.Count); Console.WriteLine("Capacity: " + list.Capacity); Console.WriteLine("Min: " + list.Min()); Console.WriteLine("Max: " + list.Max()); }
public static void Main() { GenericList<int> test = new GenericList<int>(2); test.Add(1); test.Add(2); test.Add(10); test.Add(99); test.Add(22); test.Add(40); test.Add(121); test.Add(23); Console.WriteLine(test); Console.WriteLine(test[3]); Console.WriteLine(test.IndexOf(121)); test.RemoveAt(3); Console.WriteLine(test); Console.WriteLine(test[3]); Console.WriteLine(test.IndexOf(121)); test.InsertAt(4, 66); Console.WriteLine(test); Console.WriteLine(test.Count); Console.WriteLine("Max: " + test.Max()); Console.WriteLine("Min: " + test.Min()); Console.WriteLine(); //var allAttributes = typeof(GenericList<>).GetCustomAttributes(typeof(VersionAttribute), false); //Console.WriteLine("Version: " + allAttributes[0]); }
public static void Main() { GenericList<int> list = new GenericList<int>(2); list.Add(1); list.Add(2); list.Add(69); list.Add(97); list.Add(64); list.Add(28); list.Add(67); list.Add(123); Console.WriteLine("List: " + list); Console.WriteLine("List[6]: " + list[6]); Console.WriteLine("Index of 67: " + list.IndexOf(67)); Console.WriteLine(); list.RemoveAt(6); Console.WriteLine("List: " + list); Console.WriteLine("List[6]: " + list[6]); Console.WriteLine("Index of 67: " + list.IndexOf(67)); Console.WriteLine(); list.InsertAt(5, 72); Console.WriteLine("List: " + list); Console.WriteLine("Count: " + list.Count); Console.WriteLine(); Console.WriteLine("Max: " + list.Max()); Console.WriteLine("Min: " + list.Min()); Console.WriteLine(); var attr = typeof(GenericList<>).GetCustomAttributes(typeof(Version), false); Console.WriteLine("Version: " + attr[0]); }
static void Main() { GenericList<int> nums = new GenericList<int>() { 1, 2, 5, 7 }; Console.WriteLine("All elements: " + nums.ToString()); Console.WriteLine("Num at index 1: " + nums[1]); nums.Remove(0); Console.WriteLine("Element at index 0 has been removed"); Console.WriteLine("Num at index 1: " + nums[1]); Console.WriteLine("The index of 5 is: " + nums.Find(5)); Console.WriteLine("Nums contains 7? " + nums.Contains(7)); for (int index = 0; index < 50; index++) { nums.Add(9); Console.Write("Element added: " + nums[nums.Count - 1]); Console.WriteLine(" Count: " + nums.Count + " Capacity: " + nums.Capacity); } nums.Insert(14, 0); nums.Insert(14, 0); nums.Insert(14, 0); nums.Insert(20, 20); Console.WriteLine(nums); Console.WriteLine("Min: " + nums.Min()); Console.WriteLine("Max: " + nums.Max()); Console.WriteLine("The version of this class is: " + nums.Version()); }
static void Main() { GenericList<string> glist = new GenericList<string>(); glist.Add("First"); glist.Add("Second"); glist.Add("Third"); glist.Add("Pesho"); glist.Add("Gosho"); glist.Add("Tosho"); glist.Insert(0, "Purvi Pesho"); Console.WriteLine(glist); Console.WriteLine("Index of \"Second\": {0}", glist.IndexOf("Second")); Console.WriteLine("Does contain \"Toshkata\": {0}", glist.Contains("Toshkata")); Console.WriteLine("Does contain \"Pesho\": {0}", glist.Contains("Pesho")); Console.WriteLine(); glist.Remove(2); glist.Remove(2); Console.WriteLine(glist); Console.WriteLine("Min Value: {0}", glist.Min()); Console.WriteLine("Max Value: {0}", glist.Max()); glist.Clear(); Console.WriteLine(glist); }
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); }
public static void Main(string[] args) { var l = new GenericList<int>(); l.Add(3); l.Add(4); l.Add(235252532); Console.WriteLine(l); l.Insert(1, 2); Console.WriteLine(l); Console.WriteLine(l.Find(4)); l.RemoveAt(1); Console.WriteLine(l); l.Add(1); l.Add(7); l.Add(1); l.Add(9); l.Add(3); l.Add(2); l.Add(6); l.Add(8); Console.WriteLine(l); Console.WriteLine(l.Min()); Console.WriteLine(l.Max()); l.Clear(); Console.WriteLine(l); }
static void Main() { try { GenericList<int> list = new GenericList<int>(5); list.Add(1); list.Add(2); list.Add(1); Console.Write("Add : "); Console.WriteLine(list.ToString()); list.Remove(1); Console.Write("Remove : "); Console.WriteLine(list.ToString()); list.Insert(3, 555); Console.Write("Insert : "); Console.WriteLine(list.ToString()); Console.Write("Clear : "); list.ClearList(); Console.WriteLine(list.ToString()); Console.WriteLine("Searching element by its value"); list.Add(1); list.Add(2); list.Add(1); list.Add(2); list.Insert(2, 3); Console.WriteLine(list.ToString()); int indexOfElement = list.FindElement(1, 1); Console.WriteLine(indexOfElement); } catch (ArgumentOutOfRangeException exp) { Console.WriteLine("Error!"); Console.WriteLine(exp); } }
static void Main() { Console.WriteLine("Hello World."); Console.WriteLine("Make new List."); GenericList<float> newList = new GenericList<float>(20); Console.WriteLine("Add some numbers to the List - 5.3, 6.27, 7.55, 8, 9.09"); newList.AddElement(5.3f); newList.AddElement(6.27f); newList.AddElement(7.55f); newList.AddElement(8f); newList.AddElement(9.09f); Console.WriteLine("Print Max element: {0}", newList.Max()); Console.WriteLine("Print Min element: {0}", newList.Min()); Console.WriteLine("Add 10 in the biggining."); newList.InsertElement(0, 10); Console.WriteLine("Print Max element again: {0}", newList.Max()); Console.WriteLine("Print the List."); Console.WriteLine(newList); Console.WriteLine("Remove the fourth element."); newList.RemoveElement(3); Console.WriteLine("Print the List."); Console.WriteLine(newList); Console.WriteLine("Remove the fourth element."); newList.RemoveElement(3); Console.WriteLine("Print the List."); Console.WriteLine(newList); Console.WriteLine("Remove the fourth element."); newList.RemoveElement(3); Console.WriteLine("Print the List."); Console.WriteLine(newList); Console.WriteLine("Add 15.56 in the end."); newList.InsertElement(3, 15.56f); Console.WriteLine("Print the List."); Console.WriteLine(newList); }
static void Main() { var newList = new GenericList<int>(); for (int i = 0; i < 5; i++) { newList.Add(i); } newList.Remove(3); newList.Insert(3, 3); Console.WriteLine("For each"); foreach (var item in newList) { Console.WriteLine(item); } Console.WriteLine(); Console.WriteLine("Index of"); Console.WriteLine(newList.IndexOf(2)); Console.WriteLine(); Console.WriteLine("ToString"); Console.WriteLine(newList); Console.WriteLine(); Console.WriteLine("Min"); Console.WriteLine(newList.Min()); Console.WriteLine(); Console.WriteLine("Max"); Console.WriteLine(newList.Max()); newList.Clear(); Console.WriteLine("After clear"); Console.WriteLine(newList); Console.WriteLine("Test whatever you want!"); }
static void Main() { //Some tests. You can change values to check the correct work of the program. GenericList<int> sampleList = new GenericList<int>(5); sampleList.AddToGenericList(7); sampleList.AddToGenericList(5); sampleList.AddToGenericList(1); sampleList.AddToGenericList(70); sampleList.AddToGenericList(-7); string listElements = sampleList.ToString(); Console.WriteLine("Sample list: {0}", listElements); int element = sampleList.AcessByIndex(1); Console.WriteLine("The value of the element on index 1 is {0}", element); sampleList.RemoveByIndex(1); Console.WriteLine("Sample list: {0}", sampleList); sampleList.InsertAtPosition(2, 222); Console.WriteLine("Sample list: {0}", sampleList); int index = sampleList.FindByValue(70); Console.WriteLine("1 is on index {0}", index); int min = sampleList.Min(); int max = sampleList.Max(); Console.WriteLine("Min value - {0} \nMax value - {1}", min, max); sampleList.ClearingList(); Console.WriteLine("Sample list: {0}", sampleList); }
public void EmptyListSetCapacityTest() { GenericList<int> list = new GenericList<int>(17); Assert.AreEqual((uint)0, list.Count); Assert.AreEqual((uint)17, list.Capacity); }
static void Main() { //Create new list of strings and show functionality GenericList<string> myList = new GenericList<string>(10); myList[0] = "My"; myList[1] = "name"; myList[2] = "is"; myList[3] = "Svetlin"; myList[4] = "Nakov"; Console.WriteLine(myList); myList.Add("I like beer!"); Console.WriteLine(myList[5]); myList.RemoveByIndex(2); // remove 'is' Console.WriteLine(myList[2]); //print 'Svetlin' myList.Insert(2, "my name"); Console.WriteLine(myList[2]); Console.WriteLine(myList.IndexOfElement("name",0)); // print '1' Console.WriteLine(); Console.WriteLine(myList); myList[7] = "aaa"; myList[8] = "bbb"; myList[9] = myList.Max(myList[7], myList[8]); Console.WriteLine(myList[9]); //print 'bbb' //Create new list of strings and show functionality GenericList<int> otherList = new GenericList<int>(3); Console.WriteLine(otherList[0]); }
static void Main() { IGenericList<decimal> decimals = new GenericList<decimal>(); decimals.Add(0.0001m); Console.WriteLine(decimals); Console.WriteLine(decimals.Version()); }
static void Main() { var elements = new GenericList <int>(); // empty GenericList 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(Environment.NewLine + 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(Environment.NewLine + elements); Console.WriteLine("Count: {0}", elements.Count); Console.WriteLine("Capacity: {0}", elements.Capacity); // Contains, IndexOf Console.WriteLine(Environment.NewLine + "Contain element 2: {0}", elements.Contains(2)); Console.WriteLine("Index of element 3: {0}", elements.IndexOf(3)); // Max, Min Console.WriteLine(Environment.NewLine + "Min: {0}", elements.Min()); Console.WriteLine("Max: {0}", elements.Max()); }
static void Main() { GenericList <int> list = new GenericList <int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Add(1); list.Add(2); list.Add(3); list.Add(4); Console.WriteLine(list); list.InsertAt(7, 66); Console.WriteLine(list); list.Clear(); Console.WriteLine(list); list.Add(1); list.Add(2); list.Add(3); list.Add(4); Console.WriteLine(list); list.InsertAt(3, 66); Console.WriteLine(list); Console.WriteLine(list.FindIndex(3)); Console.WriteLine(list.HasValue(66)); list.RemoveAt(3); Console.WriteLine(list); Console.WriteLine(list.HasValue(66)); Console.WriteLine(list.Min()); Console.WriteLine(list.Max()); Console.WriteLine(); var allAttributes = typeof(GenericList <>).GetCustomAttributes(typeof(VersionAttribute), false); Console.WriteLine("Version: " + allAttributes[0]); }
public bool Remove(T item) { if (ProxyRemove != null) { return(ProxyRemove(item)); } else if (GenericList != null) { return(GenericList.Remove(item)); } else if (NonGenericList != null) { NonGenericList.Remove(item); return(true); } else { throw new NotImplementedException(); } }
public void TestListClear() { Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); // Add a new movie to the list Assert.True(Config.Client.ListAddMovieAsync(TestListId, IdHelper.MadMaxFuryRoad).Result); // Get list and check if the item was added GenericList listAfterAdd = Config.Client.GetListAsync(TestListId).Result; Assert.True(listAfterAdd.Items.Any(m => m.Id == IdHelper.MadMaxFuryRoad)); // Clear the list Assert.True(Config.Client.ListClearAsync(TestListId).Result); // Get list and check that all items were removed GenericList listAfterRemove = Config.Client.GetListAsync(TestListId).Result; Assert.False(listAfterRemove.Items.Any()); }
static void Main(string[] args) { GenericList <object> list = new GenericList <object>(); // Add items to list. list.AddHead("some string here"); list.AddHead(DateTime.Today.ToLongDateString()); list.AddHead(13); list.AddHead(13.005); for (int x = 0; x < 10; x++) { list.AddHead(x); } // Enumerate list. foreach (object i in list) { Console.WriteLine(i + " " + i.GetType()); } Console.WriteLine("\nDone"); }
static void Main(string[] args) { GenericList <int> listNumber = new GenericList <int>(); for (int x = 0; x < 10; x++) { listNumber.Add(x); } foreach (int i in listNumber) { Console.Write(i + " "); } foreach (int i in listNumber) { if (listNumber.Equal(3, i)) { Console.WriteLine("Have a element equal to input!."); } } }
private static void Main(string[] args) { var numbers = new GenericList <int>(); numbers.Add(123); var test = new GenericList <object>(); test.Add(new { Name = "asd" }); var test2 = new GenericDictionary <string, object>(); test2.Add("asd", new { Name = "asd" }); var test3 = new Nullable <int>(); System.Console.WriteLine("Has value: {0}, Value: {1}", test3.HasValue, test3.GetValueOrDefault()); //var test3 = new Nullable<int>(5); //System.Console.WriteLine("Has value: {0}, Value: {1}", test3.HasValue, test3.GetValueOrDefault()); }
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()); }
protected void Page_Load(object sender, EventArgs e) { list = new GenericList(Context); list.type = "Survey"; list.table = "TblSurvey"; list.idField = "fSurveyID"; list.fields.Add(new Field("fSurveyLabel", "Name", FieldType.String, 80, 100)); Field fUnit = new Field("fSurveyTypeRef", "Type", FieldType.Combo, 50, 50); fUnit.lookUpTable = "TblSurveyType"; fUnit.lookUpFieldID = "fSurveyTypeID"; fUnit.lookUpFieldName = "fSurveyTypeName"; list.fields.Add(fUnit); list.fields.Add(new Field("fSurveyDesc", "Description", FieldType.Paragraph, 80, 100)); list.filterFields.Add("fSurveyLabel"); list.filterFields.Add("fSurveyDesc"); list.listFilter = "fSystem != 1"; list.InitList(Context); }
public static void FileTotwolist(GenericList <int> ds1, GenericList <int> ds2) { using (StreamReader sr = new StreamReader("Dayso1.txt")) { var n = int.Parse(sr.ReadLine()); for (int i = 0; i < n; i++) { var x = int.Parse(sr.ReadLine()); ds1.AddLast(x); } } using (StreamReader sr1 = new StreamReader("Dayso2.txt")) { var n = int.Parse(sr1.ReadLine()); for (int i = 0; i < n; i++) { var x = int.Parse(sr1.ReadLine()); ds2.AddLast(x); } } }
static void Main(string[] args) { GenericList <int> arrayc = new GenericList <int>(4); arrayc.add(2); arrayc.add(3); Console.WriteLine(arrayc); Console.WriteLine(arrayc.contains(3)); arrayc.insert(14, 4); Console.WriteLine(arrayc); Console.WriteLine("The min value is {0}", arrayc.Min()); Console.WriteLine("The max value is {0}", arrayc.Max()); Console.WriteLine(arrayc.FindIndex(14)); arrayc.clear(); Console.WriteLine(arrayc); }
protected void Page_Load(object sender, EventArgs e) { list = new GenericList(Context); list.type = "Vocabulary"; list.table = "TblVocabulary"; list.idField = "fVocabularyID"; list.fields.Add(new Field("fVocabularyName", "Name", FieldType.String, 80, 100)); Field fUnit = new Field("fVocabularyInterfaceID", "Type", FieldType.Combo, 50, 50); fUnit.lookUpTable = "TblVocabularyInterface"; fUnit.lookUpFieldID = "fVocabularyInterfaceID"; fUnit.lookUpFieldName = "fVocabularyInterfaceName"; list.fields.Add(fUnit); list.fields.Add(new Field("fVocabularyURL", "URL", FieldType.Link, 80, 100)); list.filterFields.Add("fVocabularyName"); list.filterFields.Add("fVocabularyURL"); list.InitList(Context); }
public void TestListCreateAndDelete() { const string listName = "Test List 123"; Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); string newListId = Config.Client.ListCreateAsync(listName).Result; Assert.False(string.IsNullOrWhiteSpace(newListId)); GenericList newlyAddedList = Config.Client.GetListAsync(newListId).Result; Assert.NotNull(newlyAddedList); Assert.Equal(listName, newlyAddedList.Name); Assert.Equal("", newlyAddedList.Description); // "" is the default value Assert.Equal("en", newlyAddedList.Iso_639_1); // en is the default value Assert.Equal(0, newlyAddedList.ItemCount); Assert.Equal(0, newlyAddedList.Items.Count); Assert.False(string.IsNullOrWhiteSpace(newlyAddedList.CreatedBy)); Assert.True(Config.Client.ListDeleteAsync(newListId).Result); }
protected void Page_Load(object sender, EventArgs e) { list = new GenericList(Context); list.publishButtons = true; list.exportButton = false; list.type = "Catalogue"; list.table = "TblCatalogue"; list.idField = "fCatalogueID"; list.fields.Add(new Field("fCatalogueName", "Name", FieldType.String, 80, 100)); Field fUnit = new Field("fTemplateID", "Template", FieldType.Combo, 50, 50); fUnit.lookUpTable = "TblTemplate"; fUnit.lookUpFieldID = "fTemplateID"; fUnit.lookUpFieldName = "fTemplateName"; list.fields.Add(fUnit); list.fields.Add(new Field("", "Taxonomy", FieldType.TaxonList, 0, 0, "")); list.InitList(Context); }
/// <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() { // Declare a list of type int. GenericList <int> list1 = new GenericList <int>(); list1.Add(1); // Declare a list of type string. GenericList <string> list2 = new GenericList <string>(); list2.Add(""); // Declare a list of type ExampleClass. GenericList <ExampleClass> list3 = new GenericList <ExampleClass>(); list3.Add(new ExampleClass()); /**/ TestSwap(); /**/ // Use the generic method. // ... Specifying the type parameter is optional here. // ... Then print the results. List <bool> list1_ = GetInitializedList(true, 5); List <string> list2_ = GetInitializedList <string>("Perls", 3); foreach (bool value in list1_) { Console.WriteLine(value); } foreach (string value in list2_) { Console.WriteLine(value); } }
static void Main() { //create instance GenericList <int> genericList = new GenericList <int>(); //add elements for (int i = 0; i < 16; i++) { genericList.Add(i); } Console.WriteLine(genericList); //remove elements for (int i = 0; i < 5; i++) { genericList.RemoveAt(i); } Console.WriteLine(genericList); //insert at position genericList.Insert(1, 32); genericList.Insert(16, 1); Console.WriteLine(genericList); //Find min and max Console.WriteLine(genericList.Min()); Console.WriteLine(genericList.Max()); Console.WriteLine(genericList.Count); Console.WriteLine(genericList.Capacity); //clear genericList.Clear(); Console.WriteLine(genericList.Count); Console.WriteLine(genericList.Capacity); }
public static FormularioModel GetFormularioXSeleccion(MotivoModel motivo, NegocioModel negocio) { Query supQuery = new Query(); CompositeTest where = new CompositeTest(); where.SetOperator(CompositeTest.AND); where.Add(new AttributeTest("idMotivo", motivo.IdMotivo, AttributeTest.EQUAL)); where.Add(new AttributeTest("idNegocio", negocio.IdNegocio, AttributeTest.EQUAL)); supQuery.Where(where); GenericList <SeleccionFormulario> seleccionFormulario = SeleccionFormulario.FindWithQuery(supQuery); if (seleccionFormulario.Size() > 0) { return(FormularioModel.Create(seleccionFormulario[0].Formulario)); } else { return(null); } }
public MethodName(MethodInfo method, TypeNameFlag flags) { Method = method; ReturnType = TypeNameFactory.Create(method.ReturnType, flags); Name = method.Name; ExplicitInterface = null; Generics = new GenericList(); if (method.IsGenericMethod) { foreach (var generic in method.GetGenericArguments()) { Generics.Add(TypeNameFactory.Create(generic, flags)); } } Parameters = new ParameterList(); foreach (var parameter in method.GetParameters()) { Parameters.Add(new ParameterName(parameter, flags)); } }
static void Main() { GenericList <int> listInt = new GenericList <int>(2); listInt.Add(2); listInt.Add(3); listInt.Add(4); listInt.Add(5); listInt.Add(6); listInt.Add(7); listInt.Insert(55, 3); Console.WriteLine(listInt.ToString()); Console.WriteLine(listInt.FindElemIndexByValue(123)); Console.WriteLine(listInt.Min()); Console.WriteLine(listInt.Max()); listInt.Clear(); Console.WriteLine(listInt.ToString()); }
/// <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() { // Screen bounds details . Use this information to set up game objects positions. var screenBounds = GraphicsDevice.Viewport.Bounds; PaddleBottom = new Paddle(GameConstants.PaddleDefaultWidth, GameConstants.PaddleDefaulHeight, GameConstants.PaddleDefaulSpeed); PaddleBottom.X = screenBounds.Width / 2f - PaddleBottom.Width / 2f; PaddleBottom.Y = screenBounds.Bottom - PaddleBottom.Height; PaddleTop = new Paddle(GameConstants.PaddleDefaultWidth, GameConstants.PaddleDefaulHeight, GameConstants.PaddleDefaulSpeed); PaddleTop.X = GameConstants.ScreenWidth / 2 - GameConstants.PaddleDefaultWidth / 2; PaddleTop.Y = GameConstants.PaddleYOffset; Ball = new Ball(GameConstants.DefaultBallSize, GameConstants.DefaultInitialBallSpeed, GameConstants.DefaultBallBumpSpeedIncreaseFactor) { X = (float)GameConstants.ScreenWidth / 2, Y = (float)GameConstants.ScreenHeight / 2 }; Background = new Background(screenBounds.Width, screenBounds.Height); Walls = new GenericList <Wall>() { // try with 100 for default wall size ! new Wall(-GameConstants.WallDefaultSize, 0, GameConstants.WallDefaultSize, screenBounds.Height), new Wall(screenBounds.Right, 0, GameConstants.WallDefaultSize, screenBounds.Height) }; Goals = new GenericList <Wall>() { new Wall(0, screenBounds.Height, screenBounds.Width, GameConstants.WallDefaultSize), new Wall(screenBounds.Top, -GameConstants.WallDefaultSize, screenBounds.Width, GameConstants.WallDefaultSize), }; // Add our game objects to the sprites that should be drawn collection . SpritesForDrawList.Add(Background); SpritesForDrawList.Add(PaddleBottom); SpritesForDrawList.Add(PaddleTop); SpritesForDrawList.Add(Ball); base.Initialize(); }
static void Main() { GenericList <int> a = new GenericList <int>(4); Console.WriteLine(a.ToString()); GenericList <decimal> exampleB = new GenericList <decimal>(4); exampleB.AddElement(3.4231231m); exampleB.AddElement(238.47326478234m); exampleB.AddElement(-18.346287346287m); exampleB.AddElement(3.147432684m); exampleB.AddElement(2.3567894m); exampleB.AddElement(-2.2m); Console.WriteLine(exampleB[3]); Console.WriteLine("Max = {0}", exampleB.Max <decimal>()); Console.WriteLine("Min = {0}", exampleB.Min <decimal>()); Console.WriteLine(exampleB.ToString()); }
static void Main() { GenericList <int> intList = new GenericList <int>(); intList.Add(1); intList.Add(2); intList.Add(3); intList.Add(1); intList.Add(2); intList.Add(3); foreach (int num in intList) { Console.WriteLine(num); } Console.WriteLine("Number of elements: {0}", intList.Count); intList.Remove(3); foreach (int num in intList) { Console.WriteLine(num); } intList.RemoveAt(2); Console.WriteLine("Number of elements: {0}", intList.Count); foreach (int num in intList) { Console.WriteLine(num); } Console.WriteLine("Max element: {0}", intList.Max()); Console.WriteLine("Min element: {0}", intList.Min()); int element = 1; Console.WriteLine("Index of element {0} is {1}", element, intList.IndexOf(element)); intList.InsertAt(28, 1); Console.WriteLine(string.Join(", ", intList)); Console.WriteLine(intList.Contains(28)); Console.WriteLine(intList.Contains(100)); Console.WriteLine(intList); intList.Clear(); Console.WriteLine(intList); }
static void Main(string[] args) { var book = new Book { Id = 1, Name = "FixItNooo" }; var books = new GenericList <Book>(); books.Add(book); var dictionary = new GenericDictionary <string, Book>(); dictionary.Add("test", book); var number = new Generics.Nullable <int>(); Console.WriteLine("Has Value?" + number.HasValue); Console.WriteLine("Value" + number.GetValueOrDefault()); Console.WriteLine("Hello World!"); }
static void Main(string[] args) { GenericList<double> xx = new GenericList<double>(); xx.Add(90); xx.Add(160); xx.Add(280); xx.Add(450); xx.Add(550); GenericList<double> yy = new GenericList<double>(); xx.Add(1); xx.Add(2); xx.Add(3); xx.Add(4); xx.Add(50); double[] x = { 90, 160, 280, 450, 550 }; double[] y = {1, 2, 3, 4, 5}; Pearson pearson = new Pearson(); Console.WriteLine(pearson.Korelacja(x, y); Console.ReadKey(); }
public static GenericList <T> Sort <T>(GenericList <T> ourList) where T : IComparable <T> { bool isSorted = false; while (!isSorted) { bool elementFound = false; for (int i = 0; i < ourList.Count() - 1; i++) { if (ourList[i].CompareTo(ourList[i + 1]) > 0) { ourList.Swap(i, i + 1); elementFound = true; break; } } if (elementFound == false) { isSorted = true; } } return(ourList); }
public void ZipIntsTest() { GenericList <int> odd = new GenericList <int>() { 1, 3, 5 }; GenericList <int> even = new GenericList <int>() { 2, 4, 6 }; GenericList <int> expected = new GenericList <int>() { 1, 2, 3, 4, 5, 6 }; GenericList <int> result; result = odd.Zip(even); for (int i = 0; i < expected.Count; i++) { Assert.AreEqual(result[i], expected[i]); } }
public void TestListAddAndRemoveMovie() { Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); // Add a new movie to the list Assert.True(Config.Client.ListAddMovieAsync(TestListId, IdHelper.EvanAlmighty).Result); // Try again, this time it should fail since the list already contains this movie Assert.False(Config.Client.ListAddMovieAsync(TestListId, IdHelper.EvanAlmighty).Result); // Get list and check if the item was added GenericList listAfterAdd = Config.Client.GetListAsync(TestListId).Result; Assert.True(listAfterAdd.Items.Any(m => m.Id == IdHelper.EvanAlmighty)); // Remove the previously added movie from the list Assert.True(Config.Client.ListRemoveMovieAsync(TestListId, IdHelper.EvanAlmighty).Result); // Get list and check if the item was removed GenericList listAfterRemove = Config.Client.GetListAsync(TestListId).Result; Assert.False(listAfterRemove.Items.Any(m => m.Id == IdHelper.EvanAlmighty)); }
public async Task <IActionResult> GetBlocks(int skip, int take) { try { var blocks = await _graph.GetBlocks(skip, take); var genericList = new GenericList <BlockHeaderProto> { Data = blocks.ToList() }; var maxBytesNeeded = FlatBufferSerializer.Default.GetMaxSize(genericList); var buffer = new byte[maxBytesNeeded]; FlatBufferSerializer.Default.Serialize(genericList, buffer); return(new ObjectResult(new { flatbuffer = buffer })); } catch (Exception ex) { _logger.Here().Error(ex, "Unable to get the range"); } return(NotFound()); }
public static void Test() { //int 类型列表 GenericList <int> list1 = new GenericList <int>(); list1.Add(1); Console.WriteLine("泛型列表中加入int"); //string 类型列表 GenericList <string> list2 = new GenericList <string>(); list2.Add(""); Console.WriteLine("泛型列表中加入string"); //class 类型列表 GenericList <ExampleClass> list3 = new GenericList <ExampleClass>(); list3.Add(new ExampleClass()); Console.WriteLine("泛型列表中加入class"); }