开发者

How To Add In List Array Using Loop I am Getting Error?

Hi all i am getting only one value in list array it is not adding rows in it.. how to add rows in list array ?

for(int a=0;a<_dt.Rows.Count;a++)
{     
    double PW =Convert.ToDouble(_dt.Rows[a]["POWER"]);
    int VOL =Convert.ToInt32(_dt.Rows[a]["VOLTAGE"]);
    double PV = PW * VOL;
    List<double> res = new List<double>();
    r开发者_如何学JAVAes.Add(PV);
}

hopes for your suggestions..

Regards,


You are adding the result to a List inside the loop, but you must declare it bevor the loop:

List<double> res = new List<double>();             
for(int a=0;a<_dt.Rows.Count;a++) {
    double PW =Convert.ToDouble(_dt.Rows[a]["POWER"]);             
    int VOL =Convert.ToInt32(_dt.Rows[a]["VOLTAGE"]);             
    double PV = PW * VOL;             
    res.Add(PV);         
} 


You seem to be remaking the list each intteration. While you havent said the error, perhaps this is the root cause of your problem. Make the list (aka res) before the loop.


Everytime in the loop you are creating new instance of the List. Please take it outside the loop.

  • Justin Samuel.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜