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(); }
// 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) { 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(); }
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]); }
//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)); }