static void Main(string[] args) { double X = 2; double Y = 5; double Z = 8; List<double> num = new List<double> { X, Y, Z }; List<double> num2 = new List<double>(); //List<double> num3=new List<double>(); //List<double> num3 = num.FindAll(i > -3 && i < 5); foreach (double i in num) { if (i >= -3 && i <= 5) { num2.Add(i); } } num2.Add(15); foreach (double s in num2) Console.WriteLine(s); string otvet = num.ToString(); Console.WriteLine(otvet); // Find all computer books. List<Book> results = Books.FindAll(FindComputer); if (results.Count != 0) { DisplayResults(results, "All computer:"); } else { Console.WriteLine("\nNo books found."); } Book Books = new Book() { }; // Find all books under $10.00. results = Books.FindAll( delegate(Book bk) { return bk.Price < 10.00; } ); if (results.Count != 0) { Console.WriteLine(results + "Books under $10:"); } else { Console.WriteLine("\nNo books found."); } Console.ReadKey(); }
static void Main(string[] args) { string newWord; List<string> words = new List<string>(); Console.WriteLine("Enter EIGHT Strings:"); for (int i = 1; i <= 8; i++) { Console.Write(string.Format("Enter word #{0}: ", i)); newWord = Console.ReadLine(); words.Add(newWord); } Console.WriteLine(); Console.WriteLine("Enter a Character:"); char character = Console.ReadKey().KeyChar; //function is used here List<string> sortedWords = Sort(words, character); Console.WriteLine(); Console.WriteLine(); foreach (string sortedWord in sortedWords) { Console.WriteLine(sortedWord); } Console.ReadLine(); }
/// <summary> /// The entry point of the program, where the program control starts and ends. /// </summary> /// <param name="args">The command-line arguments.</param> public static void Main(string[] args) { List myList = new List(); myList.AddElement(12); Console.WriteLine(myList.DeleteElement(12)); Console.WriteLine(myList.DeleteElement(13)); }
// Example program. static void Main(string[] args) { List<int> list = new List<int>(); list.Add(2); list.Add(3); list.Add(4); list.Add(5); Console.WriteLine(list.Write()); }
static void Main(string[] args) { List<int> list = new List<int>(); list.AddToHead(5); list.AddToHead(4); list.AddToHead(3); list.AddToEnd(6); list.Insert(3, 2); Console.WriteLine(list.Write()); }
//function to return a list of strings starting with a specified character public static List<string> Sort(List<string> theList, char theChar) { List<string> sortedWords = new List<string>(); //loop through each element of theList strings foreach (string word in theList) { //checks if starting letter of theList element starts with theChar if (word[0].CompareTo(theChar) == 0) { //if true for the above - add the element to the sortedWords List sortedWords.Add(word); } } return sortedWords; }
public static void Main() { List list = new List(); for (int i = 0; i < 10; ++i) { list.Add(i); } list.DeleteElement(8); list.DeleteElement(9); list.DeleteElement(11); list.DeleteElement(1); list.DeleteElement(3); list.Pop(); Console.WriteLine(list.Top()); list.Print(); Console.WriteLine(list.Search(5)); Console.WriteLine(list.Search(11)); }
static void Main(string[] args) { //Дефиниции string _userinput = ""; //List List<int> list = new List<int>(); list.Add(5); list.Add(3); list.Add(9); list.Add(12); //Потребителски вход do { Console.Write("? "); _userinput = Console.ReadLine(); //Добавяне на Стойности //Преглед на List if (_userinput.Contains("show")) { Console.Write("List: "); for (int i = 0; i < list.Count; i++) { Console.Write(list[i]); if (i != list.Count -1)Console.Write(", "); { } } Console.WriteLine(); } //Размер на List } while (_userinput != "exit"); }
static void Main(string[] args) { //Declaration Only List<int> listInt = new List<int>(); //Declaration & Assignment List<int> listInt2 = new List<int>() {1,2,3,4,5,6}; listInt.Add(1); listInt.Add(1); listInt.Add(1); listInt.Add(1); listInt2.Add(1); listInt2.Add(1); listInt2.Add(1); listInt2.Add(1); Console.WriteLine(listInt[2]); }
static void Main(string[] args) { //Нужно уносить в отдельный класс. int[] array = { -1, 2, 3, 10, 56, 77, 88, 99 }; // Проверочный массив интов. List.List List = new List.List(); // Создаём экземпляр нашего класса; // Тест AddNode. PrintText($"Тестируем метод AddNode, выводим List:"); Console.ForegroundColor = ConsoleColor.Magenta; for (int i = 0; i < array.Length; i++) // С помощью цикла за полняем значениями наш список; { int value = array[i]; List.AddNode(value); // Используя метод AddNode, проверяем, работает ли FindNode; var allNodes = List.FindNode(value); Console.Write("{0} ", allNodes.Value); } Console.ResetColor(); // Тест GetCount. int leigth = List.GetCount(); // Вызываем метод GetCount, выводим в консоль длинну; int countFromClass = List.count; Console.WriteLine(); PrintText($"\nТестируем метод GetCount: GetCount = {leigth}, значение в классе {countFromClass}"); // Проверяем, работает ли GetCount; // Тест FindNode. var newNode = List.FindNode(10); PrintText($"Тестируем метод FindNode: {newNode.Value}"); // Тест AddNodeAfter. List.AddNodeAfter(newNode, 1111); var addNode = List.FindNode(1111); PrintText($"Тестируем метод AddNodeAfter: {addNode.Value}"); // Тест RemoveNode по значению. PrintText("Тестируем метод RemoveNode(Node):"); PrintText("\n List до удаления элемента:"); Console.ForegroundColor = ConsoleColor.Magenta; for (int i = 0; i < List.count; i++) { Console.Write(" {0}", List.FindValueByIndex(i)); } Console.ResetColor(); Console.WriteLine(); List.RemoveNode(List.FindNode(1111)); PrintText("\n List после удаления элемента:"); Console.ForegroundColor = ConsoleColor.Magenta; for (int i = 0; i < List.count; i++) { Console.Write(" {0}", List.FindValueByIndex(i)); } Console.ResetColor(); Console.WriteLine(); // Тест RemoveNode по индексу. Нужен общий метод. PrintText("\nТестируем метод RemoveNode(index):"); PrintText("\n List до удаления первого элемента:"); Console.ForegroundColor = ConsoleColor.Magenta; for (int i = 0; i < List.count; i++) { Console.Write(" {0}", List.FindValueByIndex(i)); } Console.ResetColor(); Console.WriteLine(); PrintText("\n List после удаления первого элемента:"); Console.ForegroundColor = ConsoleColor.Magenta; int first = 1; List.RemoveNode(first); for (int i = 0; i < List.count; i++) { Console.Write(" {0}", List.FindValueByIndex(i)); } Console.ResetColor(); Console.WriteLine(); PrintText("\n List после удаления последнего элемента:"); Console.ForegroundColor = ConsoleColor.Magenta; int last = 7; List.RemoveNode(last); for (int i = 0; i < List.count; i++) { Console.Write(" {0}", List.FindValueByIndex(i)); } Console.ResetColor(); Console.WriteLine(); PrintText("\n List после удаления среднего элемента:"); Console.ForegroundColor = ConsoleColor.Magenta; int middle = 4; List.RemoveNode(middle); for (int i = 0; i < List.count; i++) { Console.Write(" {0}", List.FindValueByIndex(i)); } Console.ResetColor(); Console.WriteLine(); }