0

エラーが発生している行は次のとおりです。

_activeType == typeof(Reticle);

Reticleクラスの定義方法は次のとおりです。一部のプロパティとメソッドはあまり意味がないかもしれませんが、クラスの定義が重要な問題になると思います。

public class Reticle : Shape
{
    #region Fields

    private readonly Path _path;       
    private bool _isClosed;
    private PointCollection _points;       

    #endregion Fields

    #region Constructors
    public Reticle()     // constructor
    {
        var geometry = new PathGeometry();
        geometry.Figures.Add(new PathFigure());
        _path = new Path { Data = geometry };
        Points = new PointCollection();           
    }
    #endregion Constructors

    #region Properties
    /// <summary>
    /// Gets or sets a value that specifies the arc roundness.
    /// </summary>
    public Geometry Data
    {
        get
        {
            return _path.Data;
        }
    }

    /// <summary>
    /// Gets or sets a value that specifies if the polygon will be closed or not.
    /// </summary>
    public bool IsClosed
    {
        get
        {
            return _isClosed;
        }
        set
        {
            _isClosed = value;

        }
    }

    /// <summary>
    /// Gets or sets a collection that contains the points of the polygon.
    /// </summary>
    public PointCollection Points
    {
        get { return _points; }
        set
        {
            _points = value;

        }
    }   

    protected override Geometry DefiningGeometry
    {
        get
        {
            return _path.Data;
        }
    }

    #endregion Properties

    #region Methods
    private static Point CreateRectangle(Point p1, Point p2, double distance, bool firstPoint)
    {
        double segmentLength = Math.Sqrt(Math.Pow((p2.X - p1.X), 2) + Math.Pow((p2.Y - p1.Y), 2));
        //The distance cannot be greater than half of the length of the segment
        if (distance > (segmentLength / 2))
            distance = segmentLength / 2;
        double rap = firstPoint ? distance / segmentLength : (segmentLength - distance) / segmentLength;
        return new Point(p1.X + (rap * (p2.X - p1.X)), p1.Y + (rap * (p2.Y - p1.Y)));
    }

    private static Point CreateCrosshair(Point p1, Point p2, double distancePercent, bool firstPoint)
    {
        double rap = firstPoint ? distancePercent / 100 : (100 - distancePercent) / 100;
        return new Point(p1.X + (rap * (p2.X - p1.X)), p1.Y + (rap * (p2.Y - p1.Y)));
    }
    #endregion Methods

    #region Other      

    #endregion Other
}

私はC#が初めてで、エラーが発生する理由がわかりません。エラーを修正する方法を知っている人はいますか?

4

2 に答える 2

7

私はあなたが意味したと思います

_activeType = typeof(Reticle);

ダブルではない==

于 2013-09-09T14:55:51.087 に答える
1

_activeType = typeof(レチクル);

== は比較演算子です (比較用)

于 2013-09-09T14:56:13.837 に答える