Encoding.Equals(Object) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Determines whether the specified Object is equal to the current instance.
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
Parameters
Returns
true
if value
is an instance of Encoding and is equal to the current instance; otherwise, false
.
Examples
The following example gets two instances of the same encoding (one by codepage and another by name), and checks their equality.
using namespace System;
using namespace System::Text;
int main()
{
// Get a UTF-32 encoding by codepage.
Encoding^ e1 = Encoding::GetEncoding( 12000 );
// Get a UTF-32 encoding by name.
Encoding^ e2 = Encoding::GetEncoding( "utf-32" );
// Check their equality.
Console::WriteLine( "e1 equals e2? {0}", e1->Equals( e2 ) );
}
/*
This code produces the following output.
e1 equals e2? True
*/
using System;
using System.Text;
public class SamplesEncoding {
public static void Main() {
// Get a UTF-32 encoding by codepage.
Encoding e1 = Encoding.GetEncoding( 12000 );
// Get a UTF-32 encoding by name.
Encoding e2 = Encoding.GetEncoding( "utf-32" );
// Check their equality.
Console.WriteLine( "e1 equals e2? {0}", e1.Equals( e2 ) );
}
}
/*
This code produces the following output.
e1 equals e2? True
*/
Imports System.Text
Public Class SamplesEncoding
Public Shared Sub Main()
' Get a UTF-32 encoding by codepage.
Dim e1 As Encoding = Encoding.GetEncoding(12000)
' Get a UTF-32 encoding by name.
Dim e2 As Encoding = Encoding.GetEncoding("utf-32")
' Check their equality.
Console.WriteLine("e1 equals e2? {0}", e1.Equals(e2))
End Sub
End Class
'This code produces the following output.
'
'e1 equals e2? True
Remarks
Two instances of Encoding are considered equal if they correspond to the same code page and their EncoderFallback
and DecoderFallback
objects are equal. In particular, derived code pages all have a code page of 0 and their fallbacks are normally null
(Nothing
in Visual Basic .NET). Thus they are all considered equal to one another. One consequence is that when Equals is used to populate a hash table, all derived encodings compare equal and fall into the same hash table slot.