c# - How to optimize appending multiple collections to a single list? -
foreach (var data in reportdata) { lstreportdataprint.addrange(data.tolist()); }
- reportdata ienumerable type contains collection of records it.
- lstreportdataprint list.
- 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
Post a Comment