venerdì 27 gennaio 2012

How To: Lambda Union

Giusto perchè è una cosa che capita sporadicamente e giusto perchè non sono più giovane come un tempo, mi pubblico questo semplice ma pur utile brano di codice.

public class Entity
{
public int id { get; set; }
public string name { get; set; }
public string description { get; set; }
}

public class EntityListA : List<Entity>
{

}

public class EntityListB : List<Entity>
{

}

class Program
{
static void Main(string[] args)
{
EntityListA aL = new EntityListA();
EntityListB bL = new EntityListB();

var es1= aL.Where(a => a.id > 1).Union (bL.Where(b => b.id > 3));

var es2_1 = aL.Where(a => a.id > 1);
var es2_2 = bL.Where(b => b.id > 3).Union(es2_1);

Console.ReadLine();
}
}


L'esempio come al soliti riporta sempre una condizione minima minima, ed in questo caso funziona come "ricordati .. si fa così "...

Nessun commento: