Apuntes
Pruebas con LINQ
Contenido del apunte (1)
Página 1
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Web;
namespace Invitaciones.Models
{
public class Test
{
public async void Prueba()
{
var client = new WebClient();
var resultado = await client.DownloadDataTaskAsync(new Uri("http://google.com"));
Console.WriteLine(resultado);
var resultado2 = await client.DownloadDataTaskAsync(new Uri("http://bing.com"));
//LINQ
var numeros = new[] {2,10,11,15,20,6,12,14};
var suma = numeros.Sum();
var personas = new[]
{
new {Nombre="Jesus",Edad=23},
new {Nombre="Jose",Edad=18}
};
//Sumar
var sumaedades = personas.Sum(x => x.Edad);
//Filtrar las personas que tienen mas de 18
var personasMayores = personas.Where(x => x.Edad > 18);
//Ordenar las personas en base a su edad
var personasOrdernadas = personas.OrderBy(x => x.Edad);
//Mezclando metodos LINQ
var persOrdM = personas
.OrderBy(x => x.Nombre)
.ThenBy(x=> x.Edad)
.Where(x => x.Edad > 18);
//El promedio
var edad = personas.Average(x => x.Edad);
var edadmaxima = personas.Max(x => x.Edad);
personas.ToList().ForEach(x=> Console.WriteLine(x.Nombre));
}
}
}
Información
- Descripción
- Apunte sobre Pruebas con LINQ, creado por Cesar Jesús Angulo el 23/01/2016.
- Creado por
- Cesar Jesús Angulo
- Visitas
- 8
- Etiquetas
- Valoración