c# - How to optimize appending multiple collections to a single list? -


foreach (var data in reportdata) {    lstreportdataprint.addrange(data.tolist()); } 
  1. reportdata ienumerable type contains collection of records it.
  2. lstreportdataprint list.
  3. reportdata conatins 500 records.

and loop taking time , want reduce it. there other way ?

i not sure if going optimize solution, can shrink single line:

lstreportdataprint.addrange(reportdata.selectmany(d => d)); 

note since addrange() takes ienumerable<t>, call of tolist() in code unnecessary: creates new copy of list<t> thrown away after call of addrange(). avoiding call should save time. however, reason why loop underperforms in code obtains data being iterated.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -