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());
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkxpbnE7CgpuYW1lc3BhY2UgQXJ0aWN1bG9zLkNhcDA0CnsKCXB1YmxpYyBzZWFsZWQgY2xhc3MgTGlucUV4cHJlc2lvbkxhbWJkYQoJewoJCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCQl7CgkJCS8vIDEuIEZ1ZW50ZSBkZSBkYXRvczoKCQkJTGlzdDxpbnQ+IG51bWVyb3MgPSBuZXcgTGlzdDxpbnQ+IHsgMCwgMSwgMiwgMywgNCwgNSwgNiwgNywgOCwgOX07CgkJCgkJCS8vIFByZWRpY2FkbzoKCQkJRnVuYzxpbnQsIGJvb2w+IHdoZXJlID0gbiA9PiBuIDwgNjsKCQkJLy8gU2VsZWNjacOzbjoKCQkJRnVuYzxpbnQsIGludD4gc2VsZWN0ID0gbiA9PiBuOwoJCQkvLyBPcmRlciBwb3I6CgkJCUZ1bmM8aW50LCBzdHJpbmc+IG9yZGVyYnkgPSBuID0+IG4gJSAyID09IDAgPyAiZXZlbiIgOiAib2RkIjsKCQkJCgkJCS8vIDIuIENvbnN1bHRhIExJTlE6CgkJCXZhciBudW1zID0gbnVtZXJvcy5XaGVyZSh3aGVyZSkuT3JkZXJCeShvcmRlcmJ5KS5TZWxlY3Qoc2VsZWN0KTsKCQkJCgkJCS8vIDMuIEVqZWN1Y2nDs24gY29uc3VsdGE6CgkJCWZvcmVhY2ggKHZhciBudW0gaW4gbnVtcykKCQkJewoJCQkJQ29uc29sZS5Xcml0ZUxpbmUgKG51bS5Ub1N0cmluZygpKTsKCQkJfQoJCX0KCX0KfQ==