Advertisement
Fhernd

TypeFunctionsExamples.cs

Mar 5th, 2016
4,415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement