GoConqr has a new look! Let us know what you think.

Notes

Pruebas con LINQ

Cesar Jesús Angulo Spanish 1 page

Content of the notes (1)

Page 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));

}

}

}

Information

Description
Note on Pruebas con LINQ, created by Cesar Jesús Angulo on 23/01/2016.
Views
8
Tags
linqc#
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?