UTF8Encoding.Equals(Object) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定指定的对象是否等于当前 UTF8Encoding 对象。
public:
override bool Equals(System::Object ^ value);
public override bool Equals (object value);
public override bool Equals (object? value);
override this.Equals : obj -> bool
Public Overrides Function Equals (value As Object) As Boolean
参数
- value
- Object
要与当前实例进行比较的对象。
返回
如果 value
是 UTF8Encoding 的一个实例并且等于当前对象,则为 true
;否则,为 false
。
示例
下面的示例使用 Equals 方法测试当前 UTF8Encoding 对象是否等于不同的 UTF8Encoding 对象。 创建并比较四 UTF8Encoding 个对象,并显示比较结果。
using namespace System;
using namespace System::Text;
void DescribeEquivalence( Boolean isEquivalent )
{
Console::WriteLine( "{0} equivalent encoding.", (isEquivalent ? (String^)"An" : "Not an") );
}
int main()
{
UTF8Encoding^ utf8 = gcnew UTF8Encoding;
UTF8Encoding^ utf8true = gcnew UTF8Encoding( true );
UTF8Encoding^ utf8truetrue = gcnew UTF8Encoding( true,true );
UTF8Encoding^ utf8falsetrue = gcnew UTF8Encoding( false,true );
DescribeEquivalence( utf8->Equals( utf8 ) );
DescribeEquivalence( utf8->Equals( utf8true ) );
DescribeEquivalence( utf8->Equals( utf8truetrue ) );
DescribeEquivalence( utf8->Equals( utf8falsetrue ) );
DescribeEquivalence( utf8true->Equals( utf8 ) );
DescribeEquivalence( utf8true->Equals( utf8true ) );
DescribeEquivalence( utf8true->Equals( utf8truetrue ) );
DescribeEquivalence( utf8true->Equals( utf8falsetrue ) );
DescribeEquivalence( utf8truetrue->Equals( utf8 ) );
DescribeEquivalence( utf8truetrue->Equals( utf8true ) );
DescribeEquivalence( utf8truetrue->Equals( utf8truetrue ) );
DescribeEquivalence( utf8truetrue->Equals( utf8falsetrue ) );
DescribeEquivalence( utf8falsetrue->Equals( utf8 ) );
DescribeEquivalence( utf8falsetrue->Equals( utf8true ) );
DescribeEquivalence( utf8falsetrue->Equals( utf8truetrue ) );
DescribeEquivalence( utf8falsetrue->Equals( utf8falsetrue ) );
}
using System;
using System.Text;
class UTF8EncodingExample {
public static void Main() {
UTF8Encoding utf8 = new UTF8Encoding();
UTF8Encoding utf8true = new UTF8Encoding(true);
UTF8Encoding utf8truetrue = new UTF8Encoding(true, true);
UTF8Encoding utf8falsetrue = new UTF8Encoding(false, true);
DescribeEquivalence(utf8.Equals(utf8));
DescribeEquivalence(utf8.Equals(utf8true));
DescribeEquivalence(utf8.Equals(utf8truetrue));
DescribeEquivalence(utf8.Equals(utf8falsetrue));
DescribeEquivalence(utf8true.Equals(utf8));
DescribeEquivalence(utf8true.Equals(utf8true));
DescribeEquivalence(utf8true.Equals(utf8truetrue));
DescribeEquivalence(utf8true.Equals(utf8falsetrue));
DescribeEquivalence(utf8truetrue.Equals(utf8));
DescribeEquivalence(utf8truetrue.Equals(utf8true));
DescribeEquivalence(utf8truetrue.Equals(utf8truetrue));
DescribeEquivalence(utf8truetrue.Equals(utf8falsetrue));
DescribeEquivalence(utf8falsetrue.Equals(utf8));
DescribeEquivalence(utf8falsetrue.Equals(utf8true));
DescribeEquivalence(utf8falsetrue.Equals(utf8truetrue));
DescribeEquivalence(utf8falsetrue.Equals(utf8falsetrue));
}
public static void DescribeEquivalence(Boolean isEquivalent) {
Console.WriteLine(
"{0} equivalent encoding.", (isEquivalent ? "An" : "Not an")
);
}
}
Imports System.Text
Class UTF8EncodingExample
Public Shared Sub Main()
Dim utf8 As New UTF8Encoding()
Dim utf8true As New UTF8Encoding(True)
Dim utf8truetrue As New UTF8Encoding(True, True)
Dim utf8falsetrue As New UTF8Encoding(False, True)
DescribeEquivalence(utf8.Equals(utf8))
DescribeEquivalence(utf8.Equals(utf8true))
DescribeEquivalence(utf8.Equals(utf8truetrue))
DescribeEquivalence(utf8.Equals(utf8falsetrue))
DescribeEquivalence(utf8true.Equals(utf8))
DescribeEquivalence(utf8true.Equals(utf8true))
DescribeEquivalence(utf8true.Equals(utf8truetrue))
DescribeEquivalence(utf8true.Equals(utf8falsetrue))
DescribeEquivalence(utf8truetrue.Equals(utf8))
DescribeEquivalence(utf8truetrue.Equals(utf8true))
DescribeEquivalence(utf8truetrue.Equals(utf8truetrue))
DescribeEquivalence(utf8truetrue.Equals(utf8falsetrue))
DescribeEquivalence(utf8falsetrue.Equals(utf8))
DescribeEquivalence(utf8falsetrue.Equals(utf8true))
DescribeEquivalence(utf8falsetrue.Equals(utf8truetrue))
DescribeEquivalence(utf8falsetrue.Equals(utf8falsetrue))
End Sub
Public Shared Sub DescribeEquivalence(isEquivalent As Boolean)
Dim phrase as String
If isEquivalent Then
phrase = "An"
Else
phrase = "Not an"
End If
Console.WriteLine("{0} equivalent encoding.", phrase)
End Sub
End Class
注解
如果满足以下所有条件,则两 UTF8Encoding 个对象被视为相等:
这两个对象都提供字节顺序标记,或者两者都不提供字节顺序标记。
这两个对象使用相同的编码器回退。
这两个对象使用相同的解码器回退。