Is both approach same ?

Posted by Harikrishna on Stack Overflow See other posts from Stack Overflow or by Harikrishna
Published on 2010-05-18T10:12:13Z Indexed on 2010/05/18 11:00 UTC
Read the original article Hit count: 227

Filed under:
|
|
|

I have one datatable which is not bindided and records are coming from the file by parsing it in the datatable dynamically every time. Now there is three columns in the datatable Marks1,Marks2 and FinalMarks. And their types is decimal. Now for making addition of columns Marks1 and Marks2 's records and store it into FinalMarks column,For that what I do is :

datatableResult.Columns["FinalMarks"].Expression="Marks1+Marks2";

It's works properly.

It can be done in other way also is

      foreach (DataRow r in datatableResult.Rows)
      {
            r["FinalMarks"]=Convert.ToDecimal(r["Marks1"])+Convert.ToDecimal(r["Marks2"]);
      }

Now I don't know that which is the best way to do this means performance wise. Is first approach same as second approach in background means is both approach same or what?

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms