Rect.Equals 方法

定义

指示两个矩形是否相等。

重载

名称 说明
Equals(Rect, Rect)

指示指定的矩形是否相等。

Equals(Object)

指示指定的对象是否等于当前矩形。

Equals(Rect)

指示指定的矩形是否等于当前矩形。

Equals(Rect, Rect)

指示指定的矩形是否相等。

public:
 static bool Equals(System::Windows::Rect rect1, System::Windows::Rect rect2);
public static bool Equals(System.Windows.Rect rect1, System.Windows.Rect rect2);
static member Equals : System.Windows.Rect * System.Windows.Rect -> bool
Public Shared Function Equals (rect1 As Rect, rect2 As Rect) As Boolean

参数

rect1
Rect

要比较的第一个矩形。

rect2
Rect

要比较的第二个矩形。

返回

如果矩形具有相同 的和 值,则为

示例

下面的示例演示如何使用 Equals(Rect, Rect) 该方法来确定一个矩形是否等于另一个矩形。

private bool rectEqualsExample2()
{
    // Create a rectangle.
    Rect myRectangle1 = new Rect();

    // The Location property specifies the coordinates of the upper left-hand 
    // corner of the rectangle. 
    myRectangle1.Location = new Point(10, 5);

    // Set the Size property of the rectangle with a width of 200
    // and a height of 50.
    myRectangle1.Size = new Size(200, 50);

    // Create second rectangle to compare to the first.
    Rect myRectangle2 = new Rect();
    myRectangle2.Location = new Point(10, 5);
    myRectangle2.Size = new Size(200, 50);

    // Using the Equals method, see if the second rectangle is 
    // the same as the first rectangle. doesEqual is true because
    // both rectangles are exactly the same in that they both have the 
    // same location and size.
    bool doesEqual = Rect.Equals(myRectangle1, myRectangle2);

    return doesEqual;
}

注解

此操作测试对象相等性。

在此比较中,两个 Double.NaN 实例被视为相等。

注释

矩形的位置和尺寸由 Double 值描述。 由于 Double 值在操作时可能会丢失精度,因此在逻辑上相等的两个值之间的比较可能会失败。

另请参阅

适用于

Equals(Object)

指示指定的对象是否等于当前矩形。

public:
 override bool Equals(System::Object ^ o);
public override bool Equals(object o);
override this.Equals : obj -> bool
Public Overrides Function Equals (o As Object) As Boolean

参数

o
Object

要与当前矩形进行比较的对象。

返回

如果为 a 且值与当前矩形相同则为 /&;否则为 < a0/&;否则为 /&;。

示例

下面的示例演示如何使用 Equals(Object) 该方法来确定矩形是否等于指定对象。

private bool rectEqualsExample1()
{
    // Create a rectangle.
    Rect myRectangle1 = new Rect();

    // The Location property specifies the coordinates of the upper left-hand 
    // corner of the rectangle. 
    myRectangle1.Location = new Point(10, 5);

    // Set the Size property of the rectangle with a width of 200
    // and a height of 50.
    myRectangle1.Size = new Size(200, 50);

    // Create second rectangle to compare to the first.
    Rect myRectangle2 = new Rect();
    myRectangle2.Location = new Point(10, 5);
    myRectangle2.Size = new Size(200, 50);

    // Using the Equals method, see if the second rectangle is the
    // same as the first rectangle. doesEqual is true because both
    // rectangles are exactly the same with respect to location and size. 
    bool doesEqual = myRectangle1.Equals(myRectangle2);

    return doesEqual;
}

注解

此操作测试对象相等性。

在此比较中,两个 Double.NaN 实例被视为相等。

注释

矩形的位置和尺寸由 Double 值描述。 由于 Double 值在操作时可能会丢失精度,因此在逻辑上相等的两个值之间的比较可能会失败。

另请参阅

适用于

Equals(Rect)

指示指定的矩形是否等于当前矩形。

public:
 bool Equals(System::Windows::Rect value);
public bool Equals(System.Windows.Rect value);
override this.Equals : System.Windows.Rect -> bool
Public Function Equals (value As Rect) As Boolean

参数

value
Rect

要与当前矩形进行比较的矩形。

返回

如果指定的矩形与当前矩形具有相同 的值, 则为

示例

下面的示例演示如何使用 Equals(Rect) 该方法来确定矩形是否等于指定的矩形。

private bool rectEqualsExample1()
{
    // Create a rectangle.
    Rect myRectangle1 = new Rect();

    // The Location property specifies the coordinates of the upper left-hand 
    // corner of the rectangle. 
    myRectangle1.Location = new Point(10, 5);

    // Set the Size property of the rectangle with a width of 200
    // and a height of 50.
    myRectangle1.Size = new Size(200, 50);

    // Create second rectangle to compare to the first.
    Rect myRectangle2 = new Rect();
    myRectangle2.Location = new Point(10, 5);
    myRectangle2.Size = new Size(200, 50);

    // Using the Equals method, see if the second rectangle is the
    // same as the first rectangle. doesEqual is true because both
    // rectangles are exactly the same with respect to location and size. 
    bool doesEqual = myRectangle1.Equals(myRectangle2);

    return doesEqual;
}

注解

此操作测试对象相等性。

在此比较中,两个 Double.NaN 实例被视为相等。

注释

矩形的位置和尺寸由 Double 值描述。 由于 Double 值在操作时可能会丢失精度,因此在逻辑上相等的两个值之间的比较可能会失败。

另请参阅

适用于