CharacterRange.Equality(CharacterRange, CharacterRange) 运算符

定义

比较两个 CharacterRange 对象。 指示两个 CharacterRange 对象的 FirstLength 值是否相等的值。

public:
 static bool operator ==(System::Drawing::CharacterRange cr1, System::Drawing::CharacterRange cr2);
public static bool operator == (System.Drawing.CharacterRange cr1, System.Drawing.CharacterRange cr2);
static member ( = ) : System.Drawing.CharacterRange * System.Drawing.CharacterRange -> bool
Public Shared Operator == (cr1 As CharacterRange, cr2 As CharacterRange) As Boolean

参数

cr1
CharacterRange

一个要比较是否相等的 CharacterRange

cr2
CharacterRange

一个要比较是否相等的 CharacterRange

返回

如果两个 CharacterRange 对象的 FirstLength 值均相同,则为 true;否则为 false

示例

以下示例演示如何使用 Equality 运算符。 若要运行此示例,请将其粘贴到 Windows 窗体中。 处理窗体的事件Paint,并从Paint事件处理方法调用 CharacterRangeEquality1 方法,作为 ePaintEventArgs传递。

private void CharacterRangeEquality1()
{

    // Declare the string to draw.
    string message = "Strings or strings; that is the question.";

    // Compare the ranges for equality. The should not be equal.
    CharacterRange range1 = 
        new CharacterRange(message.IndexOf("Strings"), "Strings".Length);
    CharacterRange range2 = 
        new CharacterRange(message.IndexOf("strings"), "strings".Length);

    if (range1 == range2)
        MessageBox.Show("The ranges are equal.");
    else
        MessageBox.Show("The ranges are not equal.");
}
Private Sub CharacterRangeEquality1() 
    
    ' Declare the string to draw.
    Dim message As String = "Strings or strings; that is the question."
    
    ' Compare the ranges for equality. The should not be equal.
    Dim range1 As New CharacterRange(message.IndexOf("Strings"), _
        "Strings".Length)
    Dim range2 As New CharacterRange(message.IndexOf("strings"), _
        "strings".Length)
    
    If range1 = range2 Then
        MessageBox.Show("The ranges are equal.")
    Else
        MessageBox.Show("The ranges are not equal.")
    End If
 
End Sub

注解

还可以使用 Equals 方法测试相等性。

此运算符的等效方法是 CharacterRange.Equals(Object)

适用于