A better way of handling the below program(may be with Take/Skip/TakeWhile.. or anything better)
I have a data table which has only one row. But it is having 44 columns. My task is to get the columns from the 4th row till the end.
Henceforth, I have done the below program that suits my requirement. (kindly note that dt is the datatable)
List<decimal> lstDr = new List<decimal>();
Enumerable.Range(0, dt.Columns.Count).ToList().ForEach(i =>
{
开发者_如何学Cif (i > 3)
lstDr.Add(Convert.ToDecimal(dt.Rows[0][i]));
}
);
There is nothing harm in the program. Works fine.
But I feel that there may be a better way of handimg the program may be with Skip ot Take or TakeWhile or anyother stuff.
I am looking for a better solution that the one I implemented.
Is it possible?
I am using c#3.0
Thanks.
This should do it:
List<Decimal> lstDr =
dt.Rows[0].ItemArray
.Skip(3)
.Select(o => Convert.ToDecimal(o))
.ToList();
精彩评论