CharacterRange.Equality(CharacterRange, CharacterRange) 運算子
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
比較兩個 CharacterRange 物件。 取得值,指出兩個 First 物件的 Length 和 CharacterRange 值是否相等。
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。
傳回
true
表示兩個 CharacterRange 物件具有相同的 First 和 Length 值,否則為 false
。
範例
下列範例示範如何使用 Equality 運算子。 若要執行此範例,請將它貼到 Windows Form 中。 處理表單的事件 Paint ,並從事件處理方法呼叫 CharacterRangeEquality1
方法 Paint ,並 e
傳遞為 PaintEventArgs 。
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)