UnicodeEncoding.Equals(Object) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定指定的 Object 是否等于当前的 UnicodeEncoding 对象。
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
是 UnicodeEncoding 的一个实例并且等于当前对象,则为 true
;否则,为 false
。
示例
下面的示例演示如何使用 Equals 该方法测试当前 UnicodeEncoding 对象是否等于其他 UnicodeEncoding 对象。 创建和比较五 UnicodeEncoding 个对象,并显示比较结果。
using namespace System;
using namespace System::Text;
void DescribeEquivalence( Boolean isEquivalent )
{
Console::WriteLine( " {0} equivalent encoding.", (isEquivalent ? (String^)"An" : "Not an") );
}
int main()
{
// Create a UnicodeEncoding without parameters.
UnicodeEncoding^ unicode = gcnew UnicodeEncoding;
// Create a UnicodeEncoding to support little-endian Byte ordering
// and include the Unicode Byte order mark.
UnicodeEncoding^ unicodeLittleEndianBOM = gcnew UnicodeEncoding( false,true );
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence( unicode->Equals( unicodeLittleEndianBOM ) );
// Create a UnicodeEncoding to support little-endian Byte ordering
// and not include the Unicode Byte order mark.
UnicodeEncoding^ unicodeLittleEndianNoBOM = gcnew UnicodeEncoding( false,false );
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence( unicode->Equals( unicodeLittleEndianNoBOM ) );
// Create a UnicodeEncoding to support big-endian Byte ordering
// and include the Unicode Byte order mark.
UnicodeEncoding^ unicodeBigEndianBOM = gcnew UnicodeEncoding( true,true );
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence( unicode->Equals( unicodeBigEndianBOM ) );
// Create a UnicodeEncoding to support big-endian Byte ordering
// and not include the Unicode Byte order mark.
UnicodeEncoding^ unicodeBigEndianNoBOM = gcnew UnicodeEncoding( true,false );
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence( unicode->Equals( unicodeBigEndianNoBOM ) );
}
using System;
using System.Text;
class UnicodeEncodingExample {
public static void Main() {
// Create a UnicodeEncoding without parameters.
UnicodeEncoding unicode = new UnicodeEncoding();
// Create a UnicodeEncoding to support little-endian byte ordering
// and include the Unicode byte order mark.
UnicodeEncoding unicodeLittleEndianBOM =
new UnicodeEncoding(false, true);
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicode.Equals(unicodeLittleEndianBOM));
// Create a UnicodeEncoding to support little-endian byte ordering
// and not include the Unicode byte order mark.
UnicodeEncoding unicodeLittleEndianNoBOM =
new UnicodeEncoding(false, false);
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicode.Equals(unicodeLittleEndianNoBOM));
// Create a UnicodeEncoding to support big-endian byte ordering
// and include the Unicode byte order mark.
UnicodeEncoding unicodeBigEndianBOM =
new UnicodeEncoding(true, true);
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicode.Equals(unicodeBigEndianBOM));
// Create a UnicodeEncoding to support big-endian byte ordering
// and not include the Unicode byte order mark.
UnicodeEncoding unicodeBigEndianNoBOM =
new UnicodeEncoding(true, false);
// Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicode.Equals(unicodeBigEndianNoBOM));
}
public static void DescribeEquivalence(Boolean isEquivalent) {
Console.WriteLine(
"{0} equivalent encoding.", (isEquivalent ? "An" : "Not an")
);
}
}
Imports System.Text
Class UnicodeEncodingExample
Public Shared Sub Main()
' Create a UnicodeEncoding without parameters.
Dim unicodeDefault As New UnicodeEncoding()
' Create a UnicodeEncoding to support little-endian byte ordering
' and include the Unicode byte order mark.
Dim unicodeLittleEndianBOM As New UnicodeEncoding(False, True)
' Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicodeDefault.Equals(unicodeLittleEndianBOM))
' Create a UnicodeEncoding to support little-endian byte ordering
' and not include the Unicode byte order mark.
Dim unicodeLittleEndianNoBOM As New UnicodeEncoding(False, False)
' Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicodeDefault.Equals(unicodeLittleEndianNoBOM))
' Create a UnicodeEncoding to support big-endian byte ordering
' and include the Unicode byte order mark.
Dim unicodeBigEndianBOM As New UnicodeEncoding(True, True)
' Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicodeDefault.Equals(unicodeBigEndianBOM))
' Create a UnicodeEncoding to support big-endian byte ordering
' and not include the Unicode byte order mark.
Dim unicodeBigEndianNoBOM As New UnicodeEncoding(True, False)
' Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
DescribeEquivalence(unicodeDefault.Equals(unicodeBigEndianNoBOM))
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
注解
如果满足以下所有条件,则两 UnicodeEncoding 个对象被视为相等:
这两个对象使用相同的字节顺序 (little-endian 或 big-endian) 。
这两个对象都提供字节顺序标记,或者两者均未提供。
这两个对象使用相同的编码器回退。
这两个对象使用相同的解码器回退。