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); } }
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); }
public static void Main() { Type type = typeof(GenericList <>); object[] attr = type.GetCustomAttributes(false); foreach (var ver in attr) { if (ver.GetType() == typeof(VersionAttribute)) { Console.WriteLine("GeneriList v{0}\n", (ver as VersionAttribute).Build); } } GenericList <int> numList = new GenericList <int>(); numList.Add(23, 77, -1); Console.WriteLine("Create a list and add to it 3 elements:\n{0}", numList); numList.Add(3, 4, 123, 0, -12, 31, -245, 125, 64, -122, 11, 77, 50, 4123, -517, 7, 12, 666); Console.WriteLine("Add to the list another 18 elements (resizes list):\n{0}", numList); numList.Remove(2); Console.WriteLine("Remove the element at index 2:\n{0}", numList); numList.Insert(2, 777); Console.WriteLine("Add element at index 2:\n{0}", numList); numList.Remove(numList.Count); Console.WriteLine("Remove the last element:\n{0}", numList); numList.Insert(numList.Count, 44); Console.WriteLine("Insert element at last position:\n{0}", numList); Console.WriteLine("Search for \"11\" in the list (-1 if not found): index {0}", numList.Find(11)); Console.WriteLine("Max element in the list: {0}", numList.Max()); Console.WriteLine("Min element in the list {0}", numList.Min()); Console.ReadKey(); }
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()); }
static void Main(string[] args) { var list = new GenericList <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; list.Version(); Console.WriteLine(list.Count); list.Add(1); Console.WriteLine(list.Count); Console.WriteLine(list.Min()); Console.WriteLine(list.Max()); Console.WriteLine(list.Contains(6)); Console.WriteLine(list.FindIndex(17)); list.Insert(21341, 12); Console.WriteLine(list); list.Remove(0); Console.WriteLine(list); list[2] = 23; Console.WriteLine(list); list.Clear(); Console.WriteLine(list); }
private static void Main() { GenericList <int> list = new GenericList <int>(); list.Add(5); list.Add(3); list.InsertAtPos(9, 4); Console.WriteLine(list[0].ToString()); Console.WriteLine(list[1].ToString()); Console.WriteLine(list[2].ToString()); int indexOfFive = list.FindFirstIndexOf(3); Console.WriteLine(indexOfFive.ToString()); Console.WriteLine(list.ToString()); Console.WriteLine(list.Min(3, 4)); Console.WriteLine(list.Max(3, 4)); list.Clear(); Console.WriteLine(list.ToString()); //VersionAttribute version = new VersionAttribute(2, 11); //ShowMessageBox(0,"Version: " + version.Major.ToString() + "." + version.Minor.ToString(), "Program information", 0); Type type = typeof(MainClass); object[] allAttributes = type.GetCustomAttributes(false); foreach (VersionAttribute attr in allAttributes) { Console.WriteLine( "This class has version {0}.{1} ", attr.Major, attr.Minor); } }
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); } }
static void Main(string[] args) { var customAttributes = typeof(GenericList <>).GetCustomAttributes(typeof(VersionAttribute), true); Console.WriteLine("This GenericList<T> class's version is {0}", customAttributes[0]); //INT LIST GenericList <int> intList = new GenericList <int>(1); //1-5 intList.Add(1); intList.Add(2); intList.Add(3); intList.Add(4); intList.Add(5); Console.WriteLine("1-5 LIST:"); Console.WriteLine(intList); //Insert intList.Insert(5, 6); intList.Insert(0, -1); intList.Insert(4, 3); Console.WriteLine("After Instert:"); Console.WriteLine(intList); //Time for some removal intList.Remove(5); intList.Remove(6); Console.WriteLine("After removal:"); Console.WriteLine(intList); //Remove comment to clear list! //intList.Clear(); //Access index Console.WriteLine("Print the list with by accessing elements' index:"); 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("Smallest element is: " + intList.Min()); Console.WriteLine("Max element is: " + intList.Max()); Console.WriteLine(); 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); } Console.WriteLine("Smallest element is: " + stringList.Min()); Console.WriteLine("Max element is: " + stringList.Max()); }