Char.Equals Method

Definition

返回一个值,该值指示此实例是否与指定的对象或 Char 值相等。Returns a value that indicates whether this instance is equal to a specified object or Char value.

Overloads

Equals(Char)

返回一个值,该值指示此实例是否等于指定的 Char 对象。Returns a value that indicates whether this instance is equal to the specified Char object.

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

Equals(Char)

返回一个值,该值指示此实例是否等于指定的 Char 对象。Returns a value that indicates whether this instance is equal to the specified Char object.

public:
 virtual bool Equals(char obj);
public bool Equals (char obj);
override this.Equals : char -> bool
Public Function Equals (obj As Char) As Boolean

Parameters

obj
Char

要与此实例进行比较的对象。An object to compare to this instance.

Returns

Boolean

如果 true 参数与此实例的值相等,则为 obj;否则为 falsetrue if the obj parameter equals the value of this instance; otherwise, false.

Implements

Remarks

此方法实现 System.IEquatable<T> 接口,并比 Char.Equals(Object) 略好,因为它不需要取消装箱 obj 参数。This method implements the System.IEquatable<T> interface, and performs slightly better than Char.Equals(Object) because it does not need to unbox the obj parameter.

See also

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

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

Parameters

obj
Object

要与此示例比较的对象,或 nullAn object to compare with this instance or null.

Returns

Boolean

如果 trueobj 的实例并且等于此实例的值,则为 Char;否则为 falsetrue if obj is an instance of Char and equals the value of this instance; otherwise, false.

Examples

下面的代码示例演示 EqualsThe following code example demonstrates Equals.

using namespace System;
int main()
{
   char chA = 'A';
   char chB = 'B';
   Console::WriteLine( chA.Equals( 'A' ) ); // Output: "True"
   Console::WriteLine( 'b'.Equals( chB ) ); // Output: "False"
}

using System;

public class EqualsSample {
    public static void Main() {
        char chA = 'A';
        char chB = 'B';

        Console.WriteLine(chA.Equals('A'));		// Output: "True"
        Console.WriteLine('b'.Equals(chB));		// Output: "False"
    }
}
Module EqualsSample

    Sub Main()

        Dim chA As Char
        chA = "A"c
        Dim chB As Char
        chB = "B"c

        Console.WriteLine(chA.Equals("A"c))     ' Output: "True"
        Console.WriteLine("b"c.Equals(chB))     ' Output: "False"

    End Sub

End Module

Remarks

此方法所执行的比较基于此实例的编码值并 obj,而不一定是其字典中的特征。The comparison performed by this method is based on the encoded values of this instance and obj, not necessarily their lexicographical characteristics.

See also

Applies to