JJMartinez

https://docs.microsoft.com/en-us/dotnet/csharp/quick-starts/

Nov 21st, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace list_quickstart
  5. {
  6.     class Program
  7.     {
  8.         #region WorkingWithStrings
  9.         static void Main(string[] args)
  10.         {
  11.             WorkingWithStrings();
  12.  
  13.             var fibonacciNumbers = new List<int> { 1, 1 };
  14.  
  15.             while (fibonacciNumbers.Count < 20)
  16.             {
  17.                 var previous = fibonacciNumbers[fibonacciNumbers.Count - 1];
  18.                 var previous2 = fibonacciNumbers[fibonacciNumbers.Count - 2];
  19.  
  20.                 fibonacciNumbers.Add(previous + previous2);
  21.             }
  22.             foreach (var item in fibonacciNumbers)
  23.                 Console.WriteLine(item);
  24.         }
  25.  
  26.         public static void WorkingWithStrings()
  27.         {
  28.             var names = new List<string> { "<name>", "Ana", "Felipe" };
  29.             foreach (var name in names)
  30.             {
  31.                 Console.WriteLine($"Hello {name.ToUpper()}!");
  32.             }
  33.  
  34.             Console.WriteLine();
  35.             names.Add("Maria");
  36.             names.Add("Bill");
  37.             names.Remove("Ana");
  38.             foreach (var name in names)
  39.             {
  40.                 Console.WriteLine($"Hello {name.ToUpper()}!");
  41.             }
  42.  
  43.             Console.WriteLine($"My name is {names[0]}");
  44.             Console.WriteLine($"I've added {names[2]} and {names[3]} to the list");
  45.  
  46.             Console.WriteLine($"The list has {names.Count} people in it");
  47.  
  48.             var index = names.IndexOf("Felipe");
  49.             Console.WriteLine($"The name {names[index]} is at index {index}");
  50.  
  51.             var notFound = names.IndexOf("Not Found");
  52.             Console.WriteLine($"When an item is not found, IndexOf returns {notFound}");
  53.  
  54.             names.Sort();
  55.             foreach (var name in names)
  56.             {
  57.                 Console.WriteLine($"Hello {name.ToUpper()}!");
  58.             }
  59.         }
  60.         #endregion
  61.     }
  62. }
Add Comment
Please, Sign In to add comment