sábado, 19 de septiembre de 2009

C# LINQ COLECCIONES

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LINQ_TEST
{
public partial class Form1 : Form
{
public class Persona
{
public string _name;
public int _edad;

public Persona(string name, int edad)
{
_name = name;
_edad = edad;

}
}

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
List<Persona> pers = new List<Persona>();

pers.Add(new Persona("Ricardo",23));
pers.Add(new Persona("aldo", 24));
pers.Add(new Persona("cristan", 26));
pers.Add(new Persona("bola", 26));
pers.Add(new Persona("joao", 19));
//Persona p = new Persona("Ricardo", 23);

var res = from p in pers
where p._edad <= 24
orderby p._edad ascending
select p;

string names = "";
foreach (var item in res)
{
names += item._name + item._edad + " ";
}
//"joao19 Ricardo23 aldo24 "
}
}
}

No hay comentarios:

Publicar un comentario