c# - Is there a simpler way to preform projection on a ListItemCollection? -
g'day all, there way preform projection on contents of list box. i'd able without having clear , add together contents of listbox have.
public static void setselectedwhere(this listbox listbox, func<listitem,bool> condition) { var queryablelist = listbox.items.cast<listitem>(); queryablelist.select(x=>condition(x)?x.selected:x.selected=false); listbox.items.clear(); listbox.items.addrange(queryablelist.toarray<listitem>()); }
and seems silly have clear out existing collection , add together contents back.
any thoughts
what plain old iteration?
foreach (listitem item in listbox.items) { item.selected = condition(item); }
linq not reply life universe , everything. particularly part of universe involves setting properties on existing objects.
c# linq optimization webforms projection
No comments:
Post a Comment