jeudi 14 octobre 2010

Linq - Juste un exemple de concaténation de texte avec Aggregate

Pour mes problèmes de mémoire, voici un petit exemple de concaténation de texte avec Linq to Object et la méthode Aggregate :

var checkedValues = 
MaCheckBoxList.Items.Cast<ListItem>()
.Where(c => c.Selected)
.Select(c => c.Value);

//On vérifie qu'il y a bien des valeurs sélectionnées
String maString = MaCheckBoxList.Count() > 0
? checkedValue.Aggregate((c, next) => c + ", " + next)
: String.Empty;


Aucun commentaire:

Enregistrer un commentaire