本文介绍了按2列对数据表进行排序,并将值存储到数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我有一个排序表,其中(
Hello, i have a sorted table with (
dt.DefaultView.Sort = "IndexSubImg 1,Distanta Euclidiana asc";
)排序方法,我需要将"Distanta Euclidiana"列中的值按排序顺序放入数组中,但是当我使用下一个代码时获取具有未排序元素顺序的数组.
) sorting method, and i need to get the valuse from the column "Distanta Euclidiana" into an array in sorted order, but when i use the next code i get the array with unsorted order of elements.
public double[] de(DataTable dt)
{
double[] d = new double[dt.Rows.Count];
int i=0;
foreach (DataRow row in dt.Rows)
{
d[i]=(double) row["Distanta Euclidiana"];
i++;
}
return d;
}
因此,据我了解,我的排序方法确实将单元格从第9行(例如)更改为第0行,依此类推,它仅将第9行移至第一个位置(或类似位置).我该如何使数组使元素正确定位?
So from what i understand my method of sorting it doesent change the cells from row 9(for example) to row 0 and so on it only moves the row 9 to first pozition (or something like that). How can i make my array to get the elemnts in right position?
推荐答案
foreach (DataRow row in dt.Rows)
对此
to this
foreach (DataRow row in dt.DefaultView)
这篇关于按2列对数据表进行排序,并将值存储到数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!