Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created September 8, 2014 03:01
Show Gist options
  • Save Fhernd/8e412d350f0a78138734 to your computer and use it in GitHub Desktop.
Save Fhernd/8e412d350f0a78138734 to your computer and use it in GitHub Desktop.
LINQ y expresiones lambda.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Articulos.Cap04
{
public sealed class LinqExpresionLambda
{
public static void Main()
{
// 1. Fuente de datos:
List<int> numeros = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
// Predicado:
Func<int, bool> where = n => n < 6;
// Selección:
Func<int, int> select = n => n;
// Order por:
Func<int, string> orderby = n => n % 2 == 0 ? "even" : "odd";
// 2. Consulta LINQ:
var nums = numeros.Where(where).OrderBy(orderby).Select(select);
// 3. Ejecución consulta:
foreach (var num in nums)
{
Console.WriteLine (num.ToString());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment