Created
August 24, 2010 17:39
-
-
Save albertein/547946 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Empleado { | |
public string Nombre { get; set; } | |
public string ApellidoPaterno { get; set; } | |
public string ApellidoMaterno { get; set; } | |
} | |
public class App { | |
public static void Main() { | |
var empleados = new List<Empleado>(); | |
//Se llena la coleccion de empleados, la implementación se deja como ejercicio al lector | |
popullateEmpleados (); | |
//Obtener arreglo de apellido paterno | |
var apellidos = empleados.Select (x => x.ApellidoPaterno).ToArray(); | |
//Resultado de la op anterior ["Apellido1", "Apellido2", ..., "Apellido N"] | |
//Obtener cadena de apellidos | |
var apellidosString = empleados.Aggregate("", | |
(elements, item) => elements += ", " + item.ApellidoPaterno).Substring(2); | |
//Resultado de la op anterior Appellido1, Apellido2, Apellido3, ..., Apellido N | |
//Ahora una pequeña probada de linq | |
var empleadosApellidadosAvila = | |
(from empleado in empleados | |
where empleado.ApellidoPaterno == "Avila" || empleado.ApellidoMaterno == "Avila" | |
select empleado).ToArrray (); | |
//El resultado es un arreglo de todos los empleados en la colección con apellido "Avila" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment