CharacterRange.Equals(Object) Metoda

Definicja

Pobiera wartość wskazującą, czy ten obiekt jest odpowiednikiem określonego obiektu.

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

Parametry

obj
Object

Obiekt do porównania z równością.

Zwraca

true aby wskazać określony obiekt jest wystąpieniem o takiej samej wartości First i Length jak to wystąpienie; w przeciwnym razie false.

Przykłady

W poniższym przykładzie pokazano, jak używać Equals metody . Aby uruchomić ten przykład, wklej go w formularzu systemu Windows. Obsłuż zdarzenie formularza Paint i wywołaj CharacterRangeEquality2 metodę z Paint metody obsługi zdarzeń, przekazując e jako PaintEventArgs.

private void CharacterRangeEquality2()
{

    // 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.Equals(range2))
        MessageBox.Show("The ranges are equal.");
    else
        MessageBox.Show("The ranges are not equal.");
}
Private Sub CharacterRangeEquality2() 
    
    ' 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.Equals(range2) Then
        MessageBox.Show("The ranges are equal.")
    Else
        MessageBox.Show("The ranges are not equal.")
    End If
 
End Sub

Uwagi

Można również użyć Equality polecenia , aby przetestować równość.

Dotyczy