fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Linq.Recipes.Ch01
  6. {
  7. public class TypeFunctionsExamples
  8. {
  9. public static void Main()
  10. {
  11. Console.WriteLine();
  12. Console.WriteLine("--- Generator Functions ---");
  13. Console.WriteLine("- Enumerable.Range -");
  14. IEnumerable<int> cubes = Enumerable.Range(1,5).Select(num => num * num);
  15. Console.WriteLine("Powers of 3 (between 1 and 5): ");
  16. foreach(int cube in cubes)
  17. {
  18. Console.Write("{0} ", cube);
  19. }
  20.  
  21. Console.WriteLine("\n");
  22. Console.WriteLine("--- Statistical Functions ---");
  23. Console.WriteLine("- Enumerable.Count -");
  24. string[] msProducts = {"Windows", "Office", "Flight Simulator", "Minecraft", "Edge"};
  25. int numberOfFruits = msProducts.Count();
  26. Console.WriteLine("Number of (some) Microsoft products: {0}", numberOfFruits);
  27.  
  28. Console.WriteLine("\n");
  29. Console.WriteLine("--- Projector Functions ---");
  30. Console.WriteLine("- Enumerable.Select -");
  31. IEnumerable<int> squares = Enumerable.Range(1, 5).Select(num => num * num);
  32. Console.WriteLine("Powers of 2 (between 1 and 5): ");
  33. foreach(int square in squares)
  34. {
  35. Console.Write("{0} ", square);
  36. }
  37.  
  38. Console.WriteLine("\n");
  39. Console.WriteLine("--- Filter Functions ---");
  40. Console.WriteLine("- Enumerable.First -");
  41. Console.WriteLine("Microsoft product: {0}", msProducts.First());
  42. Console.WriteLine ();
  43. }
  44. }
  45. }
Success #stdin #stdout 0.04s 24040KB
stdin
Standard input is empty
stdout
--- Generator Functions ---
- Enumerable.Range -
Powers of 3 (between 1 and 5): 
1 4 9 16 25 

--- Statistical Functions ---
- Enumerable.Count -
Number of (some) Microsoft products: 5


--- Projector Functions ---
- Enumerable.Select -
Powers of 2 (between 1 and 5): 
1 4 9 16 25 

--- Filter Functions ---
- Enumerable.First -
Microsoft product: Windows