asp.net - Which is better way of passing string to List in c# higlighting listbox based on database values -
i appreciate if can tell me better way of defining list
, passing string it
i not sure 1 use or 1 better performance point of view
var selection = "28,2,10,30,100,51"; list<string> categories = selection.split(',').tolist(); list<string> categories = new list<string>(selection.split(','));
i want highlight listbox items based on database selection
after creating list loop through them & use following code highlight selection in multi-selection list-box in asp.net
foreach (listitem item in lstcatid.items) { if (categories.contains(item.value)) item.selected = true; }
is the best way or can done in other way enhance performance.
if using read value try using ienumerable<string>
instead if list<string>
lighter , restrictive list. when use ienumerable, give compiler chance defer work until later, possibly optimizing along way. while using linq
expressions contains
using here ienumerable
best bet. apart many times during desin pattern when want transfer list of items between 2 objects again ienumerable best bet since more restrictive.
var selection = "28,2,10,30,100,51"; ienumerable<string> categories = selection.split(','); foreach (listitem item in lstcatid.items) { if (categories.contains(item.value)) item.selected = true; }
Comments
Post a Comment