1- 类GCD
public class GCD:IComparable { //高程点X坐标 private double gcdX; public double GcdX { get { return gcdX; } set { gcdX = value; } } //高程点Y坐标 private double gcdY; public double GcdY { get { return gcdY; } set { gcdY = value; } } //高程点高程 private double gcdH; public double GcdH { get { return gcdH; } set { gcdH = value; } } //高程点实测点号,即展点号 private string gcdSCDH; public string GcdSCDH { get { return gcdSCDH; } set { gcdSCDH = value; } } //高程点投影到断面线上的点到断面零点的距离:起点距 private double gcdQDJ; public double GcdQDJ { get { return gcdQDJ; } set { gcdQDJ = value; } } //高程点与断面线的垂直距离:偏距 private double gcdPJ; public double GcdPJ { get { return gcdPJ; } set { gcdPJ = value; } } /// <summary> /// 高程点与断面零点距离:斜距 /// </summary> private double gcdXj; public double GcdXj { get { return gcdXj; } set { gcdXj = value; } } //高程点与断面零点的方位角 private double gcdDWJ; public double GcdDWJ { get { return gcdDWJ; } set { gcdDWJ = value; } } public int CompareTo(object obj) { if (obj is GCD) { GCD gcd = obj as GCD; return this.gcdQDJ.CompareTo(gcd.gcdQDJ); } throw new NotImplementedException("数据不是一个高程点"); } }
2--定义一个List<GCD> gcdDic = new List<GCD>();
使得gcdDic按照GcdQDJ排序,要使用List<T>中的Sort方法,T 必须实现IComparable接口,上述代码有所体现。
3-在程序中直接调用gcdDic.Sort()即可。
4- 显示结果
cd(s)
非数字 9.73
-54.5 10.72
-51.0 10.70
-51.0 10.70
-49.7 10.62
-47.3 8.69
-45.5 8.34
-44.0 7.76
-42.6 7.76
-41.1 8.30
-40.0 8.69
-40.0 8.69
-37.7 10.20
-37.7 10.20
-34.8 10.49
-31.4 10.49
-29.2 10.04
-21.2 6.78
-20.3 6.30
-19.2 5.94
-18.2 5.76
-17.0 5.60
-15.2 5.53
-12.7 5.53
-11.0 5.67
-10.0 5.90
-9.0 6.20
-8.0 6.78
-5.1 8.62
-5.0 8.62
-2.3 8.88
-2.3 8.88
0.0 9.73
6.4 9.77
10.0 9.12
15.6 9.12
18.7 7.80
21.9 7.65
21.9 7.65
24.0 7.43