Encoding.Equals Method (System.Text)

Switch View :
ScriptFree
.NET Framework Class Library
Encoding.Equals Method

Determines whether the specified Object is equal to the current instance.

Namespace:  System.Text
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic
Public Overrides Function Equals ( _
	value As Object _
) As Boolean
C#
public override bool Equals(
	Object value
)
Visual C++
public:
virtual bool Equals(
	Object^ value
) override
F#
abstract Equals : 
        value:Object -> bool 
override Equals : 
        value:Object -> bool 

Parameters

value
Type: System.Object
The Object to compare with the current instance.

Return Value

Type: System.Boolean
true if value is an instance of Encoding and is equal to the current instance; otherwise, false.
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.

Examples

The following example gets two instances of the same encoding (one by codepage and another by name), and checks their equality.

Visual Basic

Imports System
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 'Main 

End Class 'SamplesEncoding


'This code produces the following output.
'
'e1 equals e2? True



C#

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

*/



Visual C++

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

*/


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference