Char.Equals 方法
定義
多載
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)
public:
virtual bool Equals(char obj);
public bool Equals (char obj);
override this.Equals : char -> bool
Public Function Equals (obj As Char) As Boolean
參數
- obj
- Char
與這個執行個體相比較的物件。An object to compare to this instance.
傳回
當 true
參數等於這個執行個體的值時為 obj
,否則為 false
。true
if the obj
parameter equals the value of this instance; otherwise, false
.
實作
備註
這個方法會實作為 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.
另請參閱
適用於
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);
public override bool Equals (object? obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean
參數
- obj
- Object
與這個執行個體或 null
相比較的物件。An object to compare with this instance or null
.
傳回
如果 obj
是 Char 的執行個體,並且等於這個執行個體的值,則為 true
,否則為 false
。true
if obj
is an instance of Char and equals the value of this instance; otherwise, false
.
範例
下列程式碼範例將示範 Equals 。The 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
備註
這個方法所執行的比較是以這個實例的編碼值為基礎 obj
,而不一定是其字典式特性。The comparison performed by this method is based on the encoded values of this instance and obj
, not necessarily their lexicographical characteristics.