我写了个结构    public struct Coordinate
    {
        // Data
        private double x;
        private double y;        // Operator
        public static implicit operator PointF(Coordinate c)
        {
            return new PointF((float)c.X, (float)c.Y);
        }        // ...
    }如何在 将Coordinate[] 转换为 PointF[]

解决方案 »

  1.   

    想实现索引器:?
     public struct Coordinate
        {
            // Data
            private double x;
            private double y;        private Dictionary<int, Coordinate> dict = new Dictionary<int, Coordinate>();
            public Coordinate this[int index]
            {
                get
                {
                    if (dict.ContainsKey(index))
                    {
                        return dict[index];
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                }
                set
                {
                    if (dict.ContainsKey(index))
                    {
                        dict[index] = value;
                    }
                    else
                    {
                        dict.Add(index, value);
                    }            }
            }
        }
      

  2.   

           public static implicit operator PointF(Coordinate c)
            {
                return new PointF((float)c.X, (float)c.Y);
            }
    //你这里并没有数组的转换操作呀?
      

  3.   

    我的意图是这样 实现这样一个转换 Coordinate[] coordinates = new Coordinate[10];
     Point[] points = (Coordinate[])coordinates;想只在 Coordinate类中添加代码完成者个转换,而不是在需要的地方遍历转换。
      

  4.   

    楼上写错了,重发我的意图是这样 实现这样一个转换  Coordinate[] coordinates = new Coordinate[10];
     Point[] points = (Point[])coordinates;想只在 Coordinate类中添加代码完成者个转换,而不是在需要的地方遍历转换。
      

  5.   

    在Coordinate增加一个将Coordinate[]转换为Point[] 静态方法不就行了吗?