static void Main() { System.Collections.ArrayList list = new System.Collections.ArrayList(); list.Add("Manesh"); list.Add("Akshay"); list.Add("Vikash"); list.Add("Anuj"); list.Add("Dharmesh"); list.Add("Raman"); Console.WriteLine("Initial arraylist contents:"); foreach (string v in list) { Console.WriteLine(v); } list.Reverse(); Console.WriteLine("Arraylist contents after reversing:"); foreach (string v in list) { Console.WriteLine(v); } list.Sort(); Console.WriteLine(list.BinarySearch("Raman")); //searcher Console.WriteLine("Arraylist contents after sorting:"); foreach (string v in list) { Console.WriteLine(v); } Console.ReadKey(); }
private void WriteQueueData() { System.Collections.ArrayList projectsTargets; projectsTargets = new System.Collections.ArrayList(); // empty file using (StreamWriter traceFile = new System.IO.StreamWriter(this.traceFileName, false)) { traceFile.AutoFlush = false; traceFile.WriteLine("<data>"); // write hierarchy projectsTargets.AddRange(this.projectTargetStack.ToArray()); projectsTargets.Reverse(); foreach (string data in projectsTargets) { traceFile.WriteLine("{0}", data); } // write messages foreach (string data in this.messageQueue.ToArray()) { traceFile.WriteLine("{0}", data); } traceFile.WriteLine("</data>"); } }
public void Reverse() { mutex.WaitOne(); try { array.Reverse(); } finally { mutex.ReleaseMutex(); } }
public static void Run(XmlDocument dom, BaseFormatter fmt) { XmlNodeList event_nodes = dom.SelectNodes("//event"); foreach (XmlNode event_node in event_nodes) { fmt.StartEvent(event_node); // Find all the objects that are required by the event XmlNodeList event_objects = event_node.SelectNodes(".//isobject/.."); // Put the nodes into a list so that they can be reversed // Printing the list in reverse makes it easier to read (IMO) System.Collections.ArrayList L = commoncs.libxml.NodeListToArrayList(event_objects); L.Reverse(); foreach (XmlNode event_object in L) { fmt.CreateObject(event_object); XmlNodeList field_nodes = event_object.SelectNodes("putfield"); foreach (XmlNode field_node in field_nodes) { fmt.StartField(event_object, field_node); XmlNodeList param_nodes = field_node.SelectNodes("params/*"); int param_count = 0; foreach (XmlNode param_node in param_nodes) { fmt.FieldParam(event_object, field_node, param_node, param_count); param_count++; } fmt.EndField(event_object, field_node); } } if (L.Count < 1) { fmt.CreateNullObject("Desc1"); } fmt.EndEvent(event_node); } }
private void btnReverse_Click(object sender, EventArgs e) { System.Collections.ArrayList student = new System.Collections.ArrayList(); student.Add("Ryu"); student.Add("Ven"); student.Add("Becky"); student.Add("Candy"); student.Reverse(); string msg = "陣列清單內容:\n"; for (int i = 0; i < student.Count; i++) { msg = msg + student[i] + "\n"; } MessageBox.Show(msg, "Reverse()方法"); }
private void WriteQueueData() { if (!this._tracingEnabled) { return; } System.IO.StreamWriter TraceFile; System.Collections.ArrayList ProjectsTargets; ProjectsTargets = new System.Collections.ArrayList(); // empty file try { TraceFile = new System.IO.StreamWriter(this._traceFileName, false); } catch { return; } TraceFile.AutoFlush = false; // write hierarchy ProjectsTargets.AddRange(this._ProjectTargetStack.ToArray()); ProjectsTargets.Reverse(); foreach (string data in ProjectsTargets) { TraceFile.WriteLine("{0}", data); } // write messages foreach (string data in this._MessageQueue.ToArray()) { TraceFile.WriteLine("{0}", data); } TraceFile.Close(); }
private void FormTableRecs_Load(object sender, EventArgs e) { StreamReader sr = File.OpenText("Records.txt"); string input = null; System.Collections.ArrayList records = new System.Collections.ArrayList(); while ((input = sr.ReadLine()) != null) { ClassResult CR = new ClassResult(ClassMoving.ToWords(input, 2)[0], Convert.ToInt32(ClassMoving.ToWords(input, 2)[1])); records.Add(CR); } sr.Close(); records.Sort(ClassResult.SortByPoint); records.Reverse(); for (int i = 0; i < records.Count; i++) { ClassResult CR = (ClassResult)records[i]; dgRecords.Rows.Add(CR.ResName, CR.ResPoint); } }
static void Main(string[] args) { System.Collections.ArrayList MyList; MyList = new System.Collections.ArrayList(); MyList.Add("aaa"); MyList.Add("Hello"); MyList.Add("bbbb"); MyList.Add("Kalle Anka"); MyList.Add("cc"); MyList.Add("Arne Anka"); Console.WriteLine("Det finns {0} värden i listan", MyList.Count); PrintArrayListValues(MyList); Console.WriteLine("===REVERSE ORDER==="); MyList.Reverse(); PrintArrayListValues(MyList); Console.WriteLine("===SORTING==="); MyList.Sort(); PrintArrayListValues(MyList); }
//Create a Set command for the identifier on top of the stack //NOTE: unlike GET, the last value on the SET stack is assumed to be the new value private void RecordStack(Type ExpectedDataType) { string total = ""; //Add the dot notation System.Collections.ArrayList thiscommand = new System.Collections.ArrayList(); foreach (string i in stack) { thiscommand.Add(i); thiscommand.Add("."); } //some string fixup thiscommand.Reverse(); thiscommand.RemoveAt(thiscommand.Count - 2); string value = (string)thiscommand[thiscommand.Count - 1]; thiscommand.RemoveAt(thiscommand.Count - 1); foreach (string i in thiscommand) { total += i; } //Total is not the name of the identifier //value is the value total = total.Substring(1); // add cmi. to all data model identifiers total = "cmi." + total; ScormSet ss = new ScormSet(total, value, ExpectedDataType); //set this on the serilization list //NOTE: we could just call the wrapper here directly wrapper.Set(ss); }
/// <summary> /// پیاده سازی اری لیست /// </summary> /// <param name="args"></param> static void Main(string[] args) { System.Collections.ArrayList oList = new System.Collections.ArrayList(); System.Console.WriteLine("List count: {0}", oList.Count.ToString()); System.Console.WriteLine("List capacity: {0}", oList.Capacity.ToString()); System.Console.WriteLine("\n----------\n"); oList.Add("Ali Reza Alavi"); oList.Add("Sara Ahmadi"); oList.Add("Sanaz Samimi"); foreach (string strCurrent in oList) { System.Console.WriteLine(strCurrent); } System.Console.WriteLine("\n----------\n"); for (int intIndex = 0; intIndex <= oList.Count - 1; intIndex++) { System.Console.WriteLine(oList[intIndex].ToString()); } System.Console.WriteLine("\n----------\n"); oList.Sort(); System.Console.WriteLine("List count: {0}", oList.Count.ToString()); System.Console.WriteLine("List capacity: {0}", oList.Capacity.ToString()); System.Console.WriteLine("\n----------\n"); oList.TrimToSize(); System.Console.WriteLine("List count: {0}", oList.Count.ToString()); System.Console.WriteLine("List capacity: {0}", oList.Capacity.ToString()); System.Console.WriteLine("\n----------\n"); oList.Clear(); foreach (string strCurrent in oList) { System.Console.WriteLine(strCurrent); } System.Console.WriteLine("\n----------\n"); oList.Add("Ali Reza Alavi2"); oList.Add("Sara Ahmadi2"); oList.Add("Sanaz Samimi2"); if (oList.Contains("Dariush Tasdighi")) { System.Console.WriteLine("List contains Dariush Tasdighi"); } else { System.Console.WriteLine("List does not contain Dariush Tasdighi"); } if (oList.Contains("Sara Ahmadi2")) { System.Console.WriteLine("List contains Sara Ahmadi"); } else { System.Console.WriteLine("List does not contain Sara Ahmadi2"); } System.Console.WriteLine("\n----------\n"); oList.Clear(); oList.Add("A"); oList.Add("B"); oList.Add("C"); oList.Add("D"); oList.Add("E"); oList.Add("F"); oList.Add("G"); oList.Add("H"); oList.Add("I"); oList.Add("J"); oList.Add("B"); oList.Remove("B"); oList.RemoveAt(1); foreach (string strCurrent in oList) { System.Console.WriteLine(strCurrent); } System.Console.WriteLine("\n----------\n"); oList.Reverse(); oList.Sort(); foreach (string strCurrent in oList) { System.Console.WriteLine(strCurrent); } System.Console.ReadLine(); }
private void ReadContext_引数リスト角() { string word; #pragma warning disable 164 label_0: #pragma warning restore 164 word = this.wreader.CurrentWord; { this.stack.Push(this.OpenMarker); } #pragma warning disable 164 label_1: #pragma warning restore 164 word = this.wreader.CurrentWord; if ((word == ")")) { this.wreader.ReadNext(); System.Collections.ArrayList list = new System.Collections.ArrayList(); while (this.stack.Count > 0) { object v = this.stack.Pop(); if (v == this.OpenMarker) { break; } list.Add(this.stack.Pop()); } list.Reverse(); this.stack.Push(list.ToArray()); return; } else { this.ReadContext_E1(); } #pragma warning disable 164 label_2: #pragma warning restore 164 word = this.wreader.CurrentWord; if ((word == ")")) { this.wreader.ReadNext(); System.Collections.ArrayList list = new System.Collections.ArrayList(); while (this.stack.Count > 0) { object v = this.stack.Pop(); if (v == this.OpenMarker) { break; } list.Add(this.stack.Pop()); } list.Reverse(); this.stack.Push(list.ToArray()); return; } else if ((word == ",")) { this.wreader.ReadNext(); } else { this.wreader.LetterReader.SetError("解析中の不明なエラー", 0, null); } #pragma warning disable 164 label_3: #pragma warning restore 164 word = this.wreader.CurrentWord; if ((word == ")") || (word == ",")) { this.wreader.LetterReader.SetError("エラー: \"',' に続く引数がありません。\"", 0, null); } else { this.ReadContext_E1(); goto label_2; } }
static void Main(string[] args) { Console.Title = "Ejercicio 27"; Random r = new Random(); #region Pilas Console.WriteLine("Pilas"); System.Collections.Stack pila = new System.Collections.Stack(); for (int i = 0; i < 20; i++) { pila.Push(r.Next(100, 200)); } Console.WriteLine("Mostrar como se ingresó"); MostrarPila(pila); Console.WriteLine("\nMostrar de forma decreciente"); pila = SortStack(pila, false); MostrarPila(pila); Console.WriteLine("\nMostrar de forma creciente"); pila = SortStack(pila, true); MostrarPila(pila); Console.ReadLine(); #endregion Console.Clear(); #region Colas Console.WriteLine("Colas"); System.Collections.Queue cola = new System.Collections.Queue(); for (int i = 0; i < 20; i++) { cola.Enqueue(r.Next(100, 200)); } Console.WriteLine("Mostrar como se ingresó"); MostrarCola(cola); Console.WriteLine("\nMostrar de forma decreciente"); cola = SortQueue(cola, true); MostrarCola(cola); Console.WriteLine("\nMostrar de forma creciente"); cola = SortQueue(cola, false); MostrarCola(cola); Console.ReadLine(); #endregion Console.Clear(); #region Listas Console.WriteLine("Listas"); System.Collections.ArrayList lista = new System.Collections.ArrayList(); for (int i = 0; i < 20; i++) { lista.Add(r.Next(100, 200)); } Console.WriteLine("Mostrar como se ingresó"); MostrarLista(lista); Console.WriteLine("\nMostrar de forma decreciente"); lista.Sort(); lista.Reverse(); MostrarLista(lista); Console.WriteLine("\nMostrar de forma creciente"); lista.Reverse(); MostrarLista(lista); Console.ReadLine(); #endregion }
public static void MostrarColeccionesNoGenerics() { Console.Clear(); Console.WriteLine("******************************"); Console.WriteLine("*****Pilas No Genéricas*******"); Console.WriteLine("******************************"); Console.ReadLine(); //DECLARO E INSTANCIO UNA COLECCION DE TIPO LIFO System.Collections.Stack pila = new System.Collections.Stack(); pila.Push(1); pila.Push(2); pila.Push(3); pila.Push(4); Console.WriteLine("Agrego elementos a la pila..."); Console.WriteLine("Utilizo pila.Push()"); Console.WriteLine("Orden de los elementos: 1 - 2 - 3 - 4"); Console.ReadLine(); Console.WriteLine("Muestro el primer elemento de la pila..."); Console.WriteLine("Utilizo pila.Peek()"); Console.ReadLine(); Console.WriteLine(pila.Peek()); Console.ReadLine(); Console.WriteLine("Muestro todos los elementos de la pila..."); Console.WriteLine("Recorro con un foreach. No saco los elementos de la pila."); Console.ReadLine(); foreach (int elemento in pila) { Console.WriteLine(elemento); } Console.ReadLine(); Console.WriteLine("Desapilo todos los elementos de la pila..."); Console.WriteLine("Utilizo pila.Pop(). Recorro con un for"); Console.ReadLine(); int cantidad = pila.Count; for (int i = 0; i < cantidad; i++) { Console.WriteLine("Elemento {0} = {1}", i, pila.Pop()); } Console.ReadLine(); Console.WriteLine("Cantidad de elementos en la pila = {0}", pila.Count); Console.ReadLine(); Console.Clear(); Console.WriteLine("******************************"); Console.WriteLine("****Colas No Genéricas********"); Console.WriteLine("******************************"); Console.ReadLine(); System.Collections.Queue cola = new System.Collections.Queue(); cola.Enqueue(1); cola.Enqueue(2); cola.Enqueue(3); cola.Enqueue(4); Console.WriteLine("Agrego elementos a la cola..."); Console.WriteLine("Utilizo pila.Enqueue()"); Console.WriteLine("Orden de los elementos: 1 - 2 - 3 - 4"); Console.ReadLine(); Console.WriteLine("Muestro el primer elemento de la cola..."); Console.WriteLine("Utilizo cola.Peek()"); Console.ReadLine(); Console.WriteLine(cola.Peek()); Console.ReadLine(); Console.WriteLine("Muestro todos los elementos de la cola..."); Console.WriteLine("Recorro con un foreach"); Console.ReadLine(); foreach (int elemento in cola) { Console.WriteLine(elemento); } Console.ReadLine(); Console.WriteLine("Saco todos los elementos de la cola..."); Console.WriteLine("Utilizo cola.Dequeue(). Recorro con un for"); Console.ReadLine(); cantidad = cola.Count; for (int i = 0; i < cantidad; i++) { Console.WriteLine("Elemento {0} = {1}", i, cola.Dequeue()); } Console.ReadLine(); Console.WriteLine("Cantidad de elementos en la cola = {0}", cola.Count); Console.ReadLine(); Console.Clear(); Console.WriteLine("******************************"); Console.WriteLine("******Listas Dinamicas********"); Console.WriteLine("******************************"); Console.ReadLine(); System.Collections.ArrayList vec = new System.Collections.ArrayList(); vec.Add(1); vec.Add(4); vec.Add(3); vec.Add(2); Console.WriteLine("Agrego elementos al ArrayList..."); Console.WriteLine("Utilizo vec.Add()"); Console.WriteLine("Orden de los elementos: 1 - 4 - 3 - 2"); Console.ReadLine(); Console.WriteLine("Muestro todos los elementos del ArrayList..."); Console.WriteLine("Recorro con un foreach"); Console.ReadLine(); foreach (int elemento in vec) { Console.WriteLine(elemento); } Console.ReadLine(); Console.WriteLine("Ordeno los elementos del ArrayList..."); Console.WriteLine("Utilizo vec.Sort(). Recorro con un for"); Console.ReadLine(); vec.Sort(); cantidad = vec.Count; for (int i = 0; i < cantidad; i++) { Console.WriteLine("Elemento {0} = {1}", i, vec[i]); } Console.ReadLine(); Console.WriteLine("Ordeno los elementos del ArrayList..."); Console.WriteLine("Utilizo vec.Reverse(). Recorro con un for"); Console.ReadLine(); vec.Reverse(); cantidad = vec.Count; for (int i = 0; i < cantidad; i++) { Console.WriteLine("Elemento {0} = {1}", i, vec[i]); } Console.ReadLine(); Console.Clear(); Console.WriteLine("******************************"); Console.WriteLine("*********HashTable************"); Console.WriteLine("******************************"); Console.ReadLine(); System.Collections.Hashtable ht = new System.Collections.Hashtable(); ht.Add(1, "valor 1"); ht.Add(4, "valor 4"); ht.Add(3, "valor 3"); ht.Add(2, "valor 2"); Console.WriteLine("Agrego elementos al HashTable..."); Console.WriteLine("Utilizo vec.Add()"); Console.WriteLine("Orden de los elementos: 1 - 4 - 3 - 2"); Console.ReadLine(); Console.WriteLine("Muestro todos los elementos del HashTable..."); Console.WriteLine("Recorro con un for"); Console.ReadLine(); cantidad = ht.Count; for (int i = 1; i <= cantidad; i++) { Console.WriteLine("Elemento {0} = {1}", i, ht[i]); } Console.ReadLine(); }
private static void MostrarColeccionesNoGenerics() { Console.Clear(); Console.WriteLine("******************************"); Console.WriteLine("*****Pilas No Genéricas*******"); Console.WriteLine("******************************"); Console.ReadLine(); //DECLARO E INSTANCIO UNA COLECCION DE TIPO LIFO System.Collections.Stack pila = new System.Collections.Stack(); pila.Push(1); pila.Push(2); pila.Push(3); pila.Push(4); Console.WriteLine("Agrego elementos a la pila..."); Console.WriteLine("Utilizo pila.Push()"); Console.WriteLine("Orden de los elementos: 1 - 2 - 3 - 4"); Console.ReadLine(); Console.WriteLine("Muestro el primer elemento de la pila..."); Console.WriteLine("Utilizo pila.Peek()"); Console.ReadLine(); Console.WriteLine(pila.Peek()); Console.ReadLine(); Console.WriteLine("Muestro todos los elementos de la pila..."); Console.WriteLine("Recorro con un foreach. No saco los elementos de la pila."); Console.ReadLine(); foreach (int elemento in pila) { Console.WriteLine(elemento); } Console.ReadLine(); Console.WriteLine("Desapilo todos los elementos de la pila..."); Console.WriteLine("Utilizo pila.Pop(). Recorro con un for"); Console.ReadLine(); int cantidad = pila.Count; for (int i = 0; i < cantidad; i++) { Console.WriteLine("Elemento {0} = {1}", i, pila.Pop()); } Console.ReadLine(); Console.WriteLine("Cantidad de elementos en la pila = {0}", pila.Count); Console.ReadLine(); Console.Clear(); Console.WriteLine("******************************"); Console.WriteLine("****Colas No Genéricas********"); Console.WriteLine("******************************"); Console.ReadLine(); System.Collections.Queue cola = new System.Collections.Queue(); cola.Enqueue(1); cola.Enqueue(2); cola.Enqueue(3); cola.Enqueue(4); Console.WriteLine("Agrego elementos a la cola..."); Console.WriteLine("Utilizo pila.Enqueue()"); Console.WriteLine("Orden de los elementos: 1 - 2 - 3 - 4"); Console.ReadLine(); Console.WriteLine("Muestro el primer elemento de la cola..."); Console.WriteLine("Utilizo cola.Peek()"); Console.ReadLine(); Console.WriteLine(cola.Peek()); Console.ReadLine(); Console.WriteLine("Muestro todos los elementos de la cola..."); Console.WriteLine("Recorro con un foreach"); Console.ReadLine(); foreach (int elemento in cola) { Console.WriteLine(elemento); } Console.ReadLine(); Console.WriteLine("Saco todos los elementos de la cola..."); Console.WriteLine("Utilizo cola.Dequeue(). Recorro con un for"); Console.ReadLine(); cantidad = cola.Count; for (int i = 0; i < cantidad; i++) { Console.WriteLine("Elemento {0} = {1}", i, cola.Dequeue()); } Console.ReadLine(); Console.WriteLine("Cantidad de elementos en la cola = {0}", cola.Count); Console.ReadLine(); Console.Clear(); Console.WriteLine("******************************"); Console.WriteLine("******Listas Dinamicas********"); Console.WriteLine("******************************"); Console.ReadLine(); System.Collections.ArrayList vec = new System.Collections.ArrayList(); vec.Add(1); vec.Add(4); vec.Add(3); vec.Add(2); Console.WriteLine("Agrego elementos al ArrayList..."); Console.WriteLine("Utilizo vec.Add()"); Console.WriteLine("Orden de los elementos: 1 - 4 - 3 - 2"); Console.ReadLine(); Console.WriteLine("Muestro todos los elementos del ArrayList..."); Console.WriteLine("Recorro con un foreach"); Console.ReadLine(); foreach (int elemento in vec) { Console.WriteLine(elemento); } Console.ReadLine(); Console.WriteLine("Ordeno los elementos del ArrayList..."); Console.WriteLine("Utilizo vec.Sort(). Recorro con un for"); Console.ReadLine(); vec.Sort(); cantidad = vec.Count; for (int i = 0; i < cantidad; i++) { Console.WriteLine("Elemento {0} = {1}", i, vec[i]); } Console.ReadLine(); Console.WriteLine("Ordeno los elementos del ArrayList..."); Console.WriteLine("Utilizo vec.Reverse(). Recorro con un for"); Console.ReadLine(); vec.Reverse(); cantidad = vec.Count; for (int i = 0; i < cantidad; i++) { Console.WriteLine("Elemento {0} = {1}", i, vec[i]); } Console.ReadLine(); Console.Clear(); Console.WriteLine("******************************"); Console.WriteLine("*********HashTable************"); Console.WriteLine("******************************"); Console.ReadLine(); System.Collections.Hashtable ht = new System.Collections.Hashtable(); ht.Add(1, "valor 1"); ht.Add(4, "valor 4"); ht.Add(3, "valor 3"); ht.Add(2, "valor 2"); Console.WriteLine("Agrego elementos al HashTable..."); Console.WriteLine("Utilizo vec.Add()"); Console.WriteLine("Orden de los elementos: 1 - 4 - 3 - 2"); Console.ReadLine(); Console.WriteLine("Muestro todos los elementos del HashTable..."); Console.WriteLine("Recorro con un for"); Console.ReadLine(); cantidad = ht.Count; for (int i = 1; i <= cantidad; i++) { Console.WriteLine("Elemento {0} = {1}", i, ht[i]); } Console.ReadLine(); }
static void Main(string[] args) { IncreaseCost[] applications = new IncreaseCost[4]; IncreaseCost app0 = new Game("Heroes3", 15, 200, "No license"); IncreaseCost app1 = new Game("Disciples", 5, 500, "Official license"); IncreaseCost app2 = new Software("Util_1", 0, 30); IncreaseCost app3 = new Software("Util_1", 0, 40); applications[0] = app0; applications[1] = app1; applications[2] = app2; applications[3] = app3; list1.AddRange(applications); list2.AddFirst(app0); list2.AddAfter(list2.First, app1); list2.AddLast(app2); list2.AddAfter(list2.Last, app3); //list1.Add(new Game("Heroes3", 15, 200, "No license")); int flag = 100; while (flag != 0) { Console.Clear(); Console.WriteLine("Меню : "); Console.WriteLine("1 – просмотр коллекции"); Console.WriteLine("2 – добавление элемента (используйте конструктор с 1-2 параметрами)"); Console.WriteLine("3 – добавление элемента по указанному индексу"); Console.WriteLine("4 – нахождение элемента с начала коллекции (переопределить метод Equals или оператор == для вашего класса – сравнение только по полю name)"); Console.WriteLine("5 – нахождение элемента с конца коллекции"); Console.WriteLine("6 – удаление элемента по индексу"); Console.WriteLine("7 – удаление элемента по значению"); Console.WriteLine("8 – реверс коллекции"); Console.WriteLine("9 – сортировка"); Console.WriteLine("10 – выполнение методов всех объектов, поддерживающих Interface2"); Console.WriteLine("11 – LinkedList просмотр коллекции"); Console.WriteLine("12 – LinkedList добавление элемента (используйте конструктор с 1-2 параметрами)"); Console.WriteLine("13 – LinkedList добавление элемента по указанному индексу"); Console.WriteLine("14 – LinkedList нахождение элемента с начала коллекции (переопределить метод Equals или оператор == для вашего класса – сравнение только по полю name)"); Console.WriteLine("15 – LinkedList нахождение элемента с конца коллекции"); Console.WriteLine("16 – LinkedList удаление элемента по индексу"); Console.WriteLine("17 – LinkedList удаление элемента по значению"); Console.WriteLine("18 – LinkedList реверс коллекции"); Console.WriteLine("19 – LinkedList сортировка"); Console.WriteLine("20 – LinkedList выполнение методов всех объектов, поддерживающих Interface2"); Console.WriteLine("0 – выход"); flag = Convert.ToInt32(Console.ReadLine()); switch (flag) { //просмотр коллекции case (1): { Console.Clear(); if (Program.list1.Count > 0) { Console.WriteLine("list1 содержит : " + list1.Count); foreach (Object obj in Program.list1) { Console.WriteLine("************************************************************"); Console.WriteLine(obj.ToString()); } } else { Console.WriteLine("list1 пустой"); } Console.ReadLine(); break; } //добавление элемента case (2): { Console.Clear(); Console.WriteLine("Теперь создаем обьект"); Console.WriteLine("Введите name"); String name = Console.ReadLine(); Console.WriteLine("Введите bugs"); int bugs = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Введите cost"); double cost = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Введите licenseAgreement"); String licenseAgreement = Console.ReadLine(); if (licenseAgreement.Equals("0")) { list1.Add(new Software(name, bugs, cost)); Console.WriteLine("Done"); Console.WriteLine("создали Software"); } else { list1.Add(new Game(name, bugs, cost, licenseAgreement)); Console.WriteLine("Done"); Console.WriteLine("создали Game"); } Console.WriteLine("И добавили в list1"); Console.ReadLine(); break; } //добавление элемента по указанному индексу case (3): { Console.Clear(); try { Console.WriteLine("Теперь создаем обьект"); Console.WriteLine("Введите name"); String name = Console.ReadLine(); Console.WriteLine("Введите bugs"); int bugs = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Введите cost"); double cost = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Введите licenseAgreement"); String licenseAgreement = Console.ReadLine(); Console.WriteLine("Введите index"); int index = Convert.ToInt32(Console.ReadLine()); if (licenseAgreement.Equals("0")) { list1.Insert(index, new Software(name, bugs, cost)); Console.WriteLine("Done"); Console.WriteLine("создали Software"); } else { list1.Insert(index, new Game(name, bugs, cost, licenseAgreement)); Console.WriteLine("Done"); Console.WriteLine("создали Game"); } Console.WriteLine("И добавили в list1"); } catch (Exception ex) { Console.WriteLine("Не могу выполнить"); } Console.ReadLine(); break; } //нахождение элемента с начала коллекции case (4): { Console.Clear(); Console.WriteLine("Находим элемент по имени name с начала"); Console.WriteLine("Введите name"); String name = Console.ReadLine(); Software finding = null; for (int i = 0; i < list1.Count; i++) { if (name.Equals(((Software)list1[i]).getName())) { finding = (Software)list1[i]; break; } } if (finding != null) { Console.WriteLine("Нашел"); if (finding is Game) { Console.WriteLine(((Game)finding).ToString()); } else { Console.WriteLine(((Software)finding).ToString()); } } else { Console.WriteLine("Не нашел"); } Console.ReadLine(); break; } //нахождение элемента с конца коллекции case (5): { Console.Clear(); Console.WriteLine("Находим элемент по имени name с конца"); Console.WriteLine("Введите name"); String name = Console.ReadLine(); Software finding = null; for (int i = list1.Count - 1; i >= 0; i--) { if (name.Equals(((Software)list1[i]).getName())) { finding = (Software)list1[i]; break; } } if (finding != null) { Console.WriteLine("Нашел"); if (finding is Game) { Console.WriteLine(((Game)finding).ToString()); } else { Console.WriteLine(((Software)finding).ToString()); } } else { Console.WriteLine("Не нашел"); } Console.ReadLine(); break; } //удаление элемента по индексу case (6): { Console.Clear(); try { Console.WriteLine("Удалим элемент по индексу"); Console.WriteLine("Введите индекс"); int index = Convert.ToInt32(Console.ReadLine()); list1.RemoveAt(index); Console.WriteLine("Эх жаль элемента"); } catch (Exception ex) { Console.WriteLine("Че-то пошло не так :)"); } Console.ReadLine(); break; } //удаление элемента по значению case (7): { Console.Clear(); try { Console.WriteLine("Удалим элемент по значению"); Console.WriteLine("Введите name"); String name = Console.ReadLine(); for (int i = 0; i < list1.Count; i++) { if (name.Equals(((Software)list1[i]).getName())) { list1.RemoveAt(i); Console.WriteLine("Эх жаль элемента"); break; } } } catch (Exception ex) { Console.WriteLine("Че-то пошло не так :)"); } Console.ReadLine(); break; } //реверс коллекции case (8): { Console.Clear(); Console.WriteLine("Произведем реверс list1"); list1.Reverse(); Console.WriteLine("Готово :)"); Console.ReadLine(); break; } //сортировка case (9): { Console.Clear(); Console.WriteLine("Отсортируем по name list1"); list1.Sort(); Console.WriteLine("Готово )"); Console.ReadLine(); break; } //выполнение методов всех объектов, поддерживающих Interface2 case (10): { Console.Clear(); foreach (IncreaseCost obj in list1) { if (obj is DecreaseCost) { Console.WriteLine("Ура"); Console.WriteLine("************************************************************"); ((DecreaseCost)obj).decreaseCost(); ((DecreaseCost)obj).information(); ((DecreaseCost)obj).statistic(); ((DecreaseCost)obj).info(); } } Console.ReadLine(); break; } //LinkedList просмотр коллекции case (11): { Console.Clear(); if (Program.list2.Count > 0) { Console.WriteLine("list2 содержит : " + list2.Count); foreach (Object obj in Program.list2) { Console.WriteLine("************************************************************"); Console.WriteLine(obj.ToString()); } } else { Console.WriteLine("list2 пустой"); } Console.ReadLine(); break; } //LinkedList добавление элемента case (12): { Console.Clear(); Console.WriteLine("Теперь создаем обьект"); Console.WriteLine("Введите name"); String name = Console.ReadLine(); Console.WriteLine("Введите bugs"); int bugs = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Введите cost"); double cost = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Введите licenseAgreement"); String licenseAgreement = Console.ReadLine(); if (licenseAgreement.Equals("0")) { list2.AddFirst(new Software(name, bugs, cost)); Console.WriteLine("Done"); Console.WriteLine("создали Software"); } else { list2.AddFirst(new Game(name, bugs, cost, licenseAgreement)); Console.WriteLine("Done"); Console.WriteLine("создали Game"); } Console.WriteLine("И добавили в list2"); Console.ReadLine(); break; } //LinkedList добавление элемента по указанному индексу case (13): { Console.Clear(); try { Console.WriteLine("Теперь создаем обьект"); Console.WriteLine("Введите name"); String name = Console.ReadLine(); Console.WriteLine("Введите bugs"); int bugs = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Введите cost"); double cost = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Введите licenseAgreement"); String licenseAgreement = Console.ReadLine(); Console.WriteLine("Введите index обьекта после котрого вставим этот"); int index = Convert.ToInt32(Console.ReadLine()); IncreaseCost obj = list2.ElementAt(index); if (licenseAgreement.Equals("0")) { list2.AddAfter(list2.Find(obj), new Software(name, bugs, cost)); Console.WriteLine("Done"); Console.WriteLine("создали Software"); } else { list2.AddAfter(list2.Find(obj), new Game(name, bugs, cost, licenseAgreement)); Console.WriteLine("Done"); Console.WriteLine("создали Game"); } Console.WriteLine("И добавили в list2"); } catch (Exception ex) { Console.WriteLine("Не могу выполнить"); } Console.ReadLine(); break; } //LinkedList нахождение элемента с начала коллекции case (14): { Console.Clear(); Console.WriteLine("Находим элемент по имени name с начала"); Console.WriteLine("Введите name"); String name = Console.ReadLine(); Software finding = null; LinkedListNode <IncreaseCost> node = list2.First; for (int i = 0; i < list2.Count; i++) { IncreaseCost obj = node.Value; if (name.Equals(((Software)obj).getName())) { finding = (Software)obj; } node = node.Next; } if (finding != null) { Console.WriteLine("Нашел"); if (finding is Game) { Console.WriteLine(((Game)finding).ToString()); } else { Console.WriteLine(((Software)finding).ToString()); } } else { Console.WriteLine("Не нашел"); } Console.ReadLine(); break; } //LinkedList нахождение элемента с конца коллекции case (15): { Console.Clear(); Console.WriteLine("Находим элемент по имени name с начала"); Console.WriteLine("Введите name"); String name = Console.ReadLine(); Software finding = null; LinkedListNode <IncreaseCost> node = list2.Last; for (int i = 0; i < list2.Count; i++) { IncreaseCost obj = node.Value; if (name.Equals(((Software)obj).getName())) { finding = (Software)obj; } node = node.Previous; } if (finding != null) { Console.WriteLine("Нашел"); if (finding is Game) { Console.WriteLine(((Game)finding).ToString()); } else { Console.WriteLine(((Software)finding).ToString()); } } else { Console.WriteLine("Не нашел"); } Console.ReadLine(); break; } //LinkedList удаление элемента по индексу case (16): { Console.Clear(); try { Console.WriteLine("Удалим элемент по индексу"); Console.WriteLine("Введите индекс"); int index = Convert.ToInt32(Console.ReadLine()); list2.Remove(list2.ElementAt(index)); Console.WriteLine("Эх жаль элемента"); } catch (Exception ex) { Console.WriteLine("Че-то пошло не так :)"); } Console.ReadLine(); break; } //LinkedList удаление элемента по значению case (17): { Console.Clear(); try { Console.WriteLine("Удалим элемент по значению"); Console.WriteLine("Введите name"); String name = Console.ReadLine(); LinkedListNode <IncreaseCost> node = list2.First; for (int i = 0; i < list2.Count; i++) { IncreaseCost obj = node.Value; if (name.Equals(((Software)obj).getName())) { list2.Remove(obj); Console.WriteLine("Эх жаль элемента"); break; } node = node.Next; } } catch (Exception ex) { Console.WriteLine("Че-то пошло не так :)"); } Console.ReadLine(); break; } //LinkedList реверс коллекции case (18): { Console.Clear(); Console.WriteLine("Произведем реверс list2"); IncreaseCost[] array = list2.ToArray(); LinkedList <IncreaseCost> list3 = new LinkedList <IncreaseCost>(); foreach (IncreaseCost obj in list2) { list3.AddFirst(obj); } list2 = list3; Console.WriteLine("Готово :)"); Console.ReadLine(); break; } //LinkedList сортировка case (19): { Console.Clear(); Console.WriteLine("Отсортируем по name list2"); IncreaseCost[] array = new IncreaseCost[list2.Count]; int i = 0; foreach (IncreaseCost obj in list2) { array[i] = obj; i++; } Array.Sort(array); list2.Clear(); for (int q = 0; q < array.Length; q++) { list2.AddLast(array[q]); } Console.WriteLine("Готово )"); Console.ReadLine(); break; } //выполнение методов всех объектов, поддерживающих Interface2 case (20): { Console.Clear(); foreach (IncreaseCost obj in list2) { if (obj is DecreaseCost) { Console.WriteLine("Ура"); Console.WriteLine("************************************************************"); ((DecreaseCost)obj).decreaseCost(); ((DecreaseCost)obj).information(); ((DecreaseCost)obj).statistic(); ((DecreaseCost)obj).info(); } } Console.ReadLine(); break; } case (0): { Console.Clear(); break; } } } }
public void Reverse() { arr.Reverse(); }
static void Main(string[] args) { // Check and get the arguments. String path, scope; VersionControlServer sourceControl; GetPathAndScope(args, out path, out scope, out sourceControl); // Retrieve and print the label history for the file. VersionControlLabel[] labels = null; Item targetFile = null; System.Collections.IEnumerable history = null; System.Collections.SortedList slChangeSets = new System.Collections.SortedList(); try { // The first three arguments here are null because we do not // want to filter by label name, scope, or owner. // Since we don't need the server to send back the items in // the label, we get much better performance by ommitting // those through setting the fourth parameter to false. DateTime dtStart = DateTime.Now; //scope = "$/PCSGlobal/DevTools/Authoring"; //string labelfilter = "RadAuthor_20060524*"; //VersionSpec vspec = VersionSpec.ParseSingleSpec("C23953", null); //labels = sourceControl.QueryLabels(labelfilter, scope, null, true, path, VersionSpec.Latest); labels = sourceControl.QueryLabels(null, scope, null, false, path, VersionSpec.Latest); //labels = sourceControl.QueryLabels(null, scope, null, true, path, VersionSpec.Latest); //labels = sourceControl.QueryLabels(labelfilter, scope, null, true, path, vspec); TimeSpan tsQueryLabels = DateTime.Now - dtStart; targetFile = sourceControl.GetItem(path); history = sourceControl.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.None, null, null, null, 1000, true, false); } catch (TeamFoundationServerException e) { // We couldn't contact the server, the item wasn't found, // or there was some other problem reported by the server, // so we stop here. Console.Error.WriteLine(e.Message); Environment.Exit(1); } if (labels.Length == 0) { Console.WriteLine("There are no labels for " + path); } else { foreach (Changeset c in history) { ChangeSetLabels csl = new ChangeSetLabels(); csl.m_csChangeset = c; slChangeSets[c.ChangesetId] = csl; VersionControlLabel[] vclChangeSetLabels = null; string s = c.ChangesetId.ToString(); VersionSpec vspec = new ChangesetVersionSpec(c.ChangesetId.ToString()); //VersionSpec vspec = VersionSpec.ParseSingleSpec("C" + c.ChangesetId.ToString(), null); //labels = sourceControl.QueryLabels(labelfilter, scope, null, true, path, VersionSpec.Latest); //labels = sourceControl.QueryLabels(labelfilter, scope, null, true, path, vspec); DateTime dtStart = DateTime.Now; vclChangeSetLabels = sourceControl.QueryLabels(null, scope, null, false, path, vspec); TimeSpan tsQueryLabels = DateTime.Now - dtStart; foreach (VersionControlLabel vclChangeSetLabel in vclChangeSetLabels) { VersionControlLabel[] vclEverything = null; vclEverything = sourceControl.QueryLabels(vclChangeSetLabel.Name, scope, null, false, path, vspec); //csl.m_alLabels.AddRange(vclEverything); } //csl.m_alLabels.AddRange(vclChangeSetLabels); } foreach (VersionControlLabel label in labels) { // Display the label's name and when it was last modified. Console.WriteLine("{0} ({1})", label.Name, label.LastModifiedDate.ToString("g")); foreach (Item item in label.Items) { if (item.ItemId != targetFile.ItemId) { //skip over any items that we don't care about continue; } ChangeSetLabels csl = slChangeSets[item.ChangesetId] as ChangeSetLabels; csl.m_alLabels.Add(label); } // For labels that actually have comments, display it. if (label.Comment.Length > 0) { Console.WriteLine(" Comment: " + label.Comment); } } //Reverse the order of everything as it is being displayed so that it looks like the VSS order System.Collections.ArrayList alReverseOrder = new System.Collections.ArrayList(slChangeSets.Values); alReverseOrder.Reverse(); foreach (ChangeSetLabels csl in alReverseOrder) { csl.m_alLabels.Reverse(); foreach (VersionControlLabel vcl in csl.m_alLabels) { Console.WriteLine(" Labeled: " + vcl.Name); } Console.WriteLine(" Checked-in: Changeset C" + csl.m_csChangeset.ChangesetId.ToString()); Console.WriteLine(" Comment: C" + csl.m_csChangeset.Comment.ToString()); } } }