Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Linq.Recipes.Ch01
- {
- public class TypeFunctionsExamples
- {
- public static void Main()
- {
- Console.WriteLine();
- Console.WriteLine("--- Generator Functions ---");
- Console.WriteLine("- Enumerable.Range -");
- IEnumerable<int> cubes = Enumerable.Range(1,5).Select(num => num * num);
- Console.WriteLine("Powers of 3 (between 1 and 5): ");
- foreach(int cube in cubes)
- {
- Console.Write("{0} ", cube);
- }
- Console.WriteLine("\n");
- Console.WriteLine("--- Statistical Functions ---");
- Console.WriteLine("- Enumerable.Count -");
- string[] msProducts = {"Windows", "Office", "Flight Simulator", "Minecraft", "Edge"};
- int numberOfFruits = msProducts.Count();
- Console.WriteLine("Number of (some) Microsoft products: {0}", numberOfFruits);
- Console.WriteLine("\n");
- Console.WriteLine("--- Projector Functions ---");
- Console.WriteLine("- Enumerable.Select -");
- IEnumerable<int> squares = Enumerable.Range(1, 5).Select(num => num * num);
- Console.WriteLine("Powers of 2 (between 1 and 5): ");
- foreach(int square in squares)
- {
- Console.Write("{0} ", square);
- }
- Console.WriteLine("\n");
- Console.WriteLine("--- Filter Functions ---");
- Console.WriteLine("- Enumerable.First -");
- Console.WriteLine("Microsoft product: {0}", msProducts.First());
- Console.WriteLine ();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement