c# - How to maintain Start and End index of DataTable -
i have datatable contains 13 rows. want create batch of 5 rows start , end index
i want create array or hashtable store start , end index
decimal remainder = decimal.divide(dsresult.tables[0].rows.count, 5); var numberofrequests = math.ceiling((decimal)remainder);
above code give me out put 3 13 records means 5+5+3
so expected array
or hashtable
below
0 0 4 1 5 9 3 10 12
first column incremental value, second column datatable row start index third column datatable row end index
please suggest me how implement this.
try this
datatable dt = new datatable(); dt.columns.add("index", typeof(int)); dt.rows.add(new object[]{1}); dt.rows.add(new object[]{2}); dt.rows.add(new object[]{3}); dt.rows.add(new object[]{4}); dt.rows.add(new object[]{5}); dt.rows.add(new object[]{6}); dt.rows.add(new object[]{7}); dt.rows.add(new object[]{8}); dt.rows.add(new object[]{9}); dt.rows.add(new object[]{10}); dt.rows.add(new object[]{11}); dt.rows.add(new object[]{12}); dt.rows.add(new object[]{13}); dt.rows.add(new object[]{14}); dt.rows.add(new object[]{15}); dt.rows.add(new object[]{16}); var results = dt.asenumerable() .select((x,i) => new {index = i, row = x}) .groupby(y => (int)(y.index/5)) .select(z => z.select(a => a.row).tolist()).tolist();
Comments
Post a Comment