Advertisement
Fhernd

LinqExpresionLambda.cs

Sep 7th, 2014
2,448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Articulos.Cap04
  6. {
  7.     public sealed class LinqExpresionLambda
  8.     {
  9.         public static void Main()
  10.         {
  11.             // 1. Fuente de datos:
  12.             List<int> numeros = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  13.        
  14.             // Predicado:
  15.             Func<int, bool> where = n => n < 6;
  16.             // Selección:
  17.             Func<int, int> select = n => n;
  18.             // Order por:
  19.             Func<int, string> orderby = n => n % 2 == 0 ? "even" : "odd";
  20.            
  21.             // 2. Consulta LINQ:
  22.             var nums = numeros.Where(where).OrderBy(orderby).Select(select);
  23.            
  24.             // 3. Ejecución consulta:
  25.             foreach (var num in nums)
  26.             {
  27.                 Console.WriteLine (num.ToString());
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement