c# - Enumerate SqlDataReader Columns -


given following code snip:

using (var reader = cmd.executereader()) {     while(reader.read())     {         var count = reader.fieldcount; // first column must name subsequent columns treated data         var data = new list<double>();         (var = 1; < count; i++)         {             data.add(convert.todouble(reader[i].tostring()));         }         barchartseries.add(new columnbarchart.columnchartseries((string)reader[0],                                                                 data));         columnchart.xaxis.categories.add((string)reader[0]);     } } 

is there easy way eliminate loop? perhaps using linq?

reader[0] string reader[0+?] double

i want pull doubles list if possible.

speed of concern suppose.

then you're focusing on entirely wrong problem.

out of things you're doing here, looping least inefficient part. more worrying you're converting double string , double. @ least fix code to:

for (var = 1; < count; i++) {     data.add(reader.getdouble(i)); } 

you create list known size, too:

list<double> data = new list<double>(count - 1); 

even then, suspect that's going irrelevant compared serialization , database access.

whatever do, something going looping. go great lengths hide looping (e.g. writing extension method iterate on values in row) - really, don't see there's wrong here.

i advise avoid micro-optimizing until you've proven there's problem. i'd utterly astonished if bit of code you're worrying bottleneck @ all. generally, should write simplest code achieves want to, decide on performance criteria , test against them. move away simple code when need to.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -