This documentation is archived and is not being maintained.

Encoding.Equals Method (Object)

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

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

public override bool Equals (
	Object value
)
public boolean Equals (
	Object value
)
public override function Equals (
	value : Object
) : boolean
Not applicable.

Parameters

value

The Object to compare with the current instance.

Return Value

true if value is an instance of Encoding and is equal to the current instance; otherwise, false.

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 a null reference (Nothing in Visual Basic)(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.

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

using System;
using System.Text;

public class SamplesEncoding  {

   public static void Main()  {

      // Get a UTF-32 encoding by codepage.
      Encoding e1 = Encoding.GetEncoding( 65005 );

      // 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

*/


import System.*;
import System.Text.*;

public class SamplesEncoding
{
    public static void main(String[] args)
    {
        // Get a UTF-32 encoding by codepage.
        Encoding e1 = Encoding.GetEncoding(65005);

        // Get a UTF-32 encoding by name.
        Encoding e2 = Encoding.GetEncoding("utf-32");

        // Check their equality.
        Console.WriteLine("e1 equals e2? {0}",
            System.Convert.ToString(e1.Equals(e2)));
    } //main
} //SamplesEncoding

/* 
This code produces the following output.

e1 equals e2? True

*/


Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: